diff options
Diffstat (limited to 'Arduino')
-rw-r--r-- | Arduino/main.c/main.c.ino | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/Arduino/main.c/main.c.ino b/Arduino/main.c/main.c.ino index 2efa972..94570bc 100644 --- a/Arduino/main.c/main.c.ino +++ b/Arduino/main.c/main.c.ino @@ -2,7 +2,7 @@ double VOLTAGE; double P150; double P100; -double load; +double load = 0; int Q150; int Q100; void setup() @@ -10,17 +10,24 @@ void setup() Wire.begin(0x00); Serial.begin(9600); Serial.println("Enter Nominal System Voltage:"); - VOLTAGE = Serial.read(); + while (Serial.available() == 0){;} + VOLTAGE = Serial.parseFloat(SKIP_ALL); Serial.print("System Voltage: "); Serial.println(VOLTAGE, DEC); - P150 = VOLTAGE/150; - P100 = VOLTAGE/100; + P150 = (VOLTAGE*VOLTAGE)/150; + P100 = (VOLTAGE*VOLTAGE)/100; Serial.println("Enter Load in kW:"); } void loop() { - load = Serial.read(); + Serial.flush(); + //while (!Serial.available()){;} + double temp = Serial.parseFloat(SKIP_ALL)*1000; + + if((temp != load)&&(temp > 0)) + { + load = temp; if(VOLTAGE <= 500) //We don't want to use the 100ohm resistors if the voltage is higher than 500 as they would draw excessive power. { Q100 = load/P100; @@ -38,8 +45,10 @@ void loop() Serial.print(" 150ohm and "); Serial.print(Q100, DEC); Serial.print(" 100ohm resistors will be activated. "); - Serial.print(load - ((P150*Q150)+(P100*Q100)),DEC); - Serial.println("kW unaccounted for."); + //Serial.print(load - ((P150*Q150)+(P100*Q100)),DEC); + Serial.print(((P150*Q150)+(P100*Q100)),DEC); + Serial.println("W Accounted for."); + } Wire.beginTransmission(0x01); //Controller Board Has Address 0x01 Wire.write((Q150 << 3) & Q150); Wire.endTransmission(); |