Professional Documents
Culture Documents
2 #include <LiquidCrystal_I2C.h>
3 LiquidCrystal_I2C lcd(0x27, 16, 2);
4
6
9
12 float current_Volts; // Voltage
13
14 unsigned long printPeriod = 1000; //Refresh rate
15 unsigned long previousMillis = 0;
16
17
18 void setup()
19 {
20 lcd.init();
21 lcd.backlight();
22 pinMode(relay, OUTPUT);
23 lcd.print("Voltage:");
24 delay(1000);
25
26 }
27
28 void loop()
29 {
30 RunningStatistics inputStats; // Easy life lines, actual calculation of the RMS requires a load of coding
31
32 while ( true )
33 {
37 if ((unsigned long)(millis() - previousMillis) >= printPeriod)
38 {
40
43
44 lcd.setCursor(9, 0);
45 lcd.print(current_Volts);
46
47 lcd.print("V");
48 }
50 if ( (current_Volts > 0) && (current_Volts < 150) )
51 {
52 lcd.setCursor(0, 1);
53 lcd.print("Under Voltage");
54 digitalWrite(relay, LOW);
55 }
57 if ( (current_Volts >= 150) && (current_Volts <= 260) )
58 {
59 lcd.setCursor(0, 1);
60 lcd.print("Normal Voltage");
61 digitalWrite(relay, HIGH);
62 }
64 if ( current_Volts > 260 )
65 {
66 lcd.setCursor(0, 1);
67 lcd.print("Over Voltage");
68 digitalWrite(relay, LOW);
69 }
70 }
71 }