diff options
author | Joshua Drake <Joshua.Ellis.Drake@gmail.com> | 2024-06-14 02:19:51 -0500 |
---|---|---|
committer | Joshua Drake <Joshua.Ellis.Drake@gmail.com> | 2024-06-14 02:19:51 -0500 |
commit | 00f8c8b96c4a73fdac7b2ebe31408ee502a315cd (patch) | |
tree | 58b62cb19c5067f9ac2b35949d22658779c2e739 /Arduino/main.c | |
parent | ed2644ef4e934f2f7cf93890760737790925a1c8 (diff) |
Diffstat (limited to 'Arduino/main.c')
-rw-r--r-- | Arduino/main.c/main.c.ino | 43 |
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."); + */ } } |