-
Notifications
You must be signed in to change notification settings - Fork 0
/
heaterController~
83 lines (68 loc) · 1.75 KB
/
heaterController~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// This an arduino sketch that gives 15m pulse from a RC ON/OFF switch that also resets if the battery voltage
// drops below 10.0V
//#define DEBUG 1
#define STANDBY 1
#define POWER 2
#define TIMEOUT 3
unsigned int state = STANDBY;
unsigned int ledPin = 13;
unsigned int duration = 900000; //ms
unsigned int buttonPin = 2;
unsigned int rxSignal = 0;
unsigned int powerLevel =0;
unsigned long startTime =millis();
float batteryVoltage;
float batteryVoltageThreshold = 11.5;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
rxSignal=!digitalRead(buttonPin);
batteryVoltage = 12.0*analogRead(A0)/1024.0;
digitalWrite(ledPin, powerLevel);
#ifdef DEBUG
Serial.print("State: ");
Serial.println(state);
Serial.print("Rx signal: ");
Serial.println(rxSignal);
Serial.print("Power level: ");
Serial.println(powerLevel);
Serial.print("Battery Voltage: ");
Serial.println(batteryVoltage);
Serial.print("On time: ");
Serial.println(millis() - startTime);
Serial.println();
#endif
delay(500);
switch (state) {
case STANDBY:
//Serial.println("STANDBY");
if (rxSignal == HIGH){
state = POWER;
powerLevel = HIGH;
startTime=millis();
}
break;
case POWER:
//Serial.println("POWER");
if (((millis() - startTime) > duration) || (rxSignal == LOW) || (batteryVoltage < batteryVoltageThreshold)) {
state = TIMEOUT;
powerLevel = LOW;
}
break;
case TIMEOUT:
powerLevel = LOW;
//Serial.println("TIMEOUT");
if (rxSignal == HIGH) {
state = TIMEOUT;
}
else {
state = STANDBY;
};
break;
};
};