summaryrefslogtreecommitdiff
path: root/Arduino/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'Arduino/main.c')
-rw-r--r--Arduino/main.c/main.c.ino134
1 files changed, 57 insertions, 77 deletions
diff --git a/Arduino/main.c/main.c.ino b/Arduino/main.c/main.c.ino
index ff5d2ee..cf6ea90 100644
--- a/Arduino/main.c/main.c.ino
+++ b/Arduino/main.c/main.c.ino
@@ -1,91 +1,71 @@
#include <Wire.h>
-double VOLTAGE;
-double P150;
-double P100;
-double load = 0;
-int Q150;
-int Q100;
-int amongus = 0;
-void setup()
+double VOLTAGE, P100, P150;
+double temp, load = 0;
+uint8_t Q100, Q150;
+bool new_message = false;
+
+void setup()
{
Wire.begin();
Serial.begin(9600);
- //Serial.println("Enter Nominal System Voltage:");
- //while (Serial.available() == 0){;}
- //VOLTAGE = Serial.parseFloat(SKIP_ALL);
- //Serial.print("System Voltage: ");
- //Serial.println(VOLTAGE, DEC);
- //P150 = (VOLTAGE*VOLTAGE)/150;
- //P100 = (VOLTAGE*VOLTAGE)/100;
- //Serial.println("Enter Load in kW:");
-
+ Serial.println("Enter Nominal System Voltage:");
+ while (Serial.available() == 0) {;}
+ VOLTAGE = Serial.parseFloat(SKIP_ALL);
+ Serial.print("System Voltage: ");
+ Serial.println(VOLTAGE, DEC);
+ P150 = (VOLTAGE * VOLTAGE) / 150;
+ P100 = (VOLTAGE * VOLTAGE) / 100;
+ Serial.println("Enter Load in kW:");
}
-void loop()
+void loop()
{
+ new_message = false;
Serial.flush();
- //while (!Serial.available()){;}
- //double temp = Serial.parseFloat(SKIP_ALL)*1000;
- //int temp = Serial.parseInt(SKIP_ALL);
- //Serial.println(temp, DEC);
-
-// 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;
-// if(Q100 > 5) Q100=5;
-// Q150 = (load - (Q100*P100))/P150;
-// }
-// else
-// {
-// Q150 = load/P150;
-// Q100 = 0;
-// }
-// if(Q150 > 15) Q150 = 15;
-// Serial.print("A combination of ");
-// Serial.print(Q150, DEC);
-// Serial.print(" 150ohm and ");
-// Serial.print(Q100, DEC);
-// Serial.print(" 100ohm resistors will be activated. ");
-// //Serial.print(load - ((P150*Q150)+(P100*Q100)),DEC);
-// Serial.print(((P150*Q150)+(P100*Q100)),DEC);
-// Serial.println("W Accounted for.");
-// }
-
+ if (Serial.available())temp = Serial.parseFloat(SKIP_ALL) * 1000;
-// delay(25);
-// Serial.print(amongus, DEC);
-// Serial.print(" ");
- Wire.requestFrom(0x30, 1);
- while(Wire.available()) {
- int c = Wire.read(); // Receive a byte as character
- Serial.println(c); // Print the character
+ 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;
+ if (Q100 > 5) Q100 = 5;
+ Q150 = (load - (Q100 * P100)) / P150;
}
- delay(100);
-//
- if(amongus > 32)amongus=0;
-// Wire.beginTransmission(0x30); //Controller Board Has Address 0x07
-//// //Wire.write((Q150 << 3) & Q150);
-// Wire.write(amongus++);
-// Wire.write(150);
-// Wire.endTransmission();
-
- //for(int x = 0; x <32;x++){
- delay(5);
- amongus++;
- //Serial.print("Increment Value");
- //Serial.println(amongus);
+ else
+ {
+ Q150 = load / P150;
+ Q100 = 0;
+ }
+ if (Q150 > 15) Q150 = 15;
+ Serial.print("A combination of ");
+ Serial.print(Q150, DEC);
+ Serial.print(" 150ohm and ");
+ Serial.print(Q100, DEC);
+ Serial.print(" 100ohm resistors will be requested. ");
+ //Serial.print(load - ((P150*Q150)+(P100*Q100)),DEC);
+ Serial.print(((P150 * Q150) + (P100 * Q100)), DEC);
+ Serial.println("W Accounted for.");
+ new_message = true;
+ }
+ delay(50);
Wire.beginTransmission(0x30); //Controller Board Has Address 0x07
- //Wire.write((Q150 << 3) & Q150);
- Wire.write(amongus);
- //Wire.write(amongus);
+ Wire.write(0x01); //First "EEPROM Address" stores resistor data.
+ Wire.write((Q100 << 4) | Q150);
Wire.endTransmission();
- delay(50);
-// Wire.beginTransmission(0x30); //Controller Board Has Address 0x07
-// //Wire.write((Q150 << 3) & Q150);
-// //Wire.write(amongus);
-// Wire.endTransmission();
+
+
+ if (new_message == true) {
+ delay(25);
+ Wire.requestFrom(0x30, 1);
+ while (!Wire.available()) {;}
+ int c = Wire.read();
+ Serial.print("Quantity of 150Ohm: ");
+ Serial.print(c & 0b00001111); //Print Q150
+ Serial.print(" Quantity of 100Ohm: ");
+ Serial.print((c & 0b01110000)>>4);
+ Serial.println(" was recieved.");
+ }
}