summaryrefslogtreecommitdiff
path: root/Arduino/main.c/main.c.ino
diff options
context:
space:
mode:
Diffstat (limited to 'Arduino/main.c/main.c.ino')
-rw-r--r--Arduino/main.c/main.c.ino43
1 files changed, 37 insertions, 6 deletions
diff --git a/Arduino/main.c/main.c.ino b/Arduino/main.c/main.c.ino
index c527c33..8f651b9 100644
--- a/Arduino/main.c/main.c.ino
+++ b/Arduino/main.c/main.c.ino
@@ -1,7 +1,8 @@
#include <Wire.h>
-double VOLTAGE, P68, P150;
-double temp, load = 0;
+bool percentageLoad = false;
+double VOLTAGE, P68, P150, PTotal;
+double temp, currentLoad, load = 0;
uint8_t Q68, Q150;
bool new_message = false;
@@ -16,14 +17,36 @@ void setup()
Serial.println(VOLTAGE, DEC);
P150 = (VOLTAGE * VOLTAGE) / 150;
P68 = (VOLTAGE * VOLTAGE) / 68;
- Serial.println("Enter Load in kW:");
+ PTotal = P150+P68;
+
+ String input = "null";
+ Serial.println("Express load as a percentage? (y/n)");
+ while ((Serial.available() == 0)||(input!="y")||(input!="n"))
+ {
+ input = Serial.readString();
+ input.trim();
+ }
+ if(input=="y")
+ {
+ percentageLoad=true;
+ Serial.print("Enter Load as a percentage of ");
+ Serial.println(PTotal, DEC);
+ }
+ else
+ {
+ percentageLoad=false;
+ Serial.println("Enter Load in kW:");
+ }
}
void loop()
{
- new_message = false;
Serial.flush();
- if (Serial.available())temp = Serial.parseFloat(SKIP_ALL) * 1000;
+ if (Serial.available())
+ {
+ if(percentageLoad) temp = Serial.parseFloat(SKIP_ALL) * 1000;
+ else temp = Serial.parseFloat(SKIP_ALL) * (PTotal/100.0);
+ }
if ((temp != load) && (temp > 0))
{
@@ -59,13 +82,21 @@ void loop()
if (new_message == true) {
delay(25);
- Wire.requestFrom(0x30, 1);
+ Wire.requestFrom(0x30, 2);
while (!Wire.available()) {;}
int c = Wire.read();
+ currentLoad = ((c & 0b00001111)*P150)+(((c & 0b01110000)>>4)*P68);
+ if(currentLoad==load)
+ {
+ new_message=false;
+ Serial.println("***Load Matched***");
+ }
+ /*
Serial.print("Quantity of 150Ohm: ");
Serial.print(c & 0b00001111); //Print Q150
Serial.print(" Quantity of 68Ohm: ");
Serial.print((c & 0b01110000)>>4);
Serial.println(" was recieved.");
+ */
}
}