Rename pins to reflect their actual buttons
This commit is contained in:
parent
fceacca2cf
commit
0da2410869
|
@ -9,10 +9,10 @@ char wifiMACAddr[18];
|
|||
const String API_ROUTE = String("http://tools-socket.protospace.ca/api/lockout/");
|
||||
|
||||
#define RELAY_PIN D1
|
||||
#define ON_BUTTON_PIN D3
|
||||
#define OFF_BUTTON_PIN D4
|
||||
#define ON_LED_PIN D6
|
||||
#define OFF_LED_PIN D7
|
||||
#define GREEN_BUTTON_PIN D3
|
||||
#define RED_BUTTON_PIN D4
|
||||
#define GREEN_LED_PIN D6
|
||||
#define RED_LED_PIN D7
|
||||
|
||||
#define RELAY_CLOSED HIGH
|
||||
#define RELAY_OPEN !RELAY_CLOSED
|
||||
|
@ -55,10 +55,10 @@ void setup()
|
|||
if (LOGGING) Serial.println("[INFO] Serial started.");
|
||||
|
||||
pinMode(RELAY_PIN, OUTPUT);
|
||||
pinMode(ON_BUTTON_PIN, INPUT_PULLUP);
|
||||
pinMode(OFF_BUTTON_PIN, INPUT_PULLUP);
|
||||
pinMode(ON_LED_PIN, OUTPUT);
|
||||
pinMode(OFF_LED_PIN, OUTPUT);
|
||||
pinMode(GREEN_BUTTON_PIN, INPUT_PULLUP);
|
||||
pinMode(RED_BUTTON_PIN, INPUT_PULLUP);
|
||||
pinMode(GREEN_LED_PIN, OUTPUT);
|
||||
pinMode(RED_LED_PIN, OUTPUT);
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
@ -116,47 +116,47 @@ void processLockState()
|
|||
{
|
||||
switch (lockState) {
|
||||
case LOCK_OFF:
|
||||
digitalWrite(ON_LED_PIN, LED_OFF);
|
||||
digitalWrite(OFF_LED_PIN, LED_ON);
|
||||
digitalWrite(GREEN_LED_PIN, LED_OFF);
|
||||
digitalWrite(RED_LED_PIN, LED_ON);
|
||||
|
||||
digitalWrite(RELAY_PIN, RELAY_OPEN);
|
||||
break;
|
||||
case LOCK_ARMED:
|
||||
digitalWrite(ON_LED_PIN, LED_OFF);
|
||||
digitalWrite(OFF_LED_PIN, LED_ON);
|
||||
digitalWrite(GREEN_LED_PIN, LED_OFF);
|
||||
digitalWrite(RED_LED_PIN, LED_ON);
|
||||
|
||||
digitalWrite(RELAY_PIN, RELAY_OPEN);
|
||||
|
||||
if (digitalRead(OFF_BUTTON_PIN) == BUTTON_CLOSED) {
|
||||
if (digitalRead(RED_BUTTON_PIN) == BUTTON_CLOSED) {
|
||||
if (LOGGING) Serial.println("[INFO] Unarming interlock.");
|
||||
lockState = LOCK_OFF_PRESSED;
|
||||
} else if (digitalRead(ON_BUTTON_PIN) == BUTTON_CLOSED) {
|
||||
} else if (digitalRead(GREEN_BUTTON_PIN) == BUTTON_CLOSED) {
|
||||
if (LOGGING) Serial.println("[INFO] On button pressed.");
|
||||
lockState = LOCK_ON_PRESSED;
|
||||
}
|
||||
break;
|
||||
case LOCK_ON_PRESSED:
|
||||
if (digitalRead(OFF_BUTTON_PIN) == BUTTON_CLOSED) {
|
||||
if (digitalRead(RED_BUTTON_PIN) == BUTTON_CLOSED) {
|
||||
if (LOGGING) Serial.println("[ERROR] Both buttons pressed, aborting.");
|
||||
lockState = LOCK_OFF_PRESSED;
|
||||
} else if (digitalRead(ON_BUTTON_PIN) == BUTTON_OPEN) {
|
||||
} else if (digitalRead(GREEN_BUTTON_PIN) == BUTTON_OPEN) {
|
||||
if (LOGGING) Serial.println("[INFO] Turning machine on.");
|
||||
lockState = LOCK_ON;
|
||||
}
|
||||
break;
|
||||
case LOCK_ON:
|
||||
digitalWrite(ON_LED_PIN, LED_ON);
|
||||
digitalWrite(OFF_LED_PIN, LED_OFF);
|
||||
digitalWrite(GREEN_LED_PIN, LED_ON);
|
||||
digitalWrite(RED_LED_PIN, LED_OFF);
|
||||
|
||||
digitalWrite(RELAY_PIN, RELAY_CLOSED);
|
||||
|
||||
if (digitalRead(OFF_BUTTON_PIN) == BUTTON_CLOSED) {
|
||||
if (digitalRead(RED_BUTTON_PIN) == BUTTON_CLOSED) {
|
||||
if (LOGGING) Serial.println("[INFO] Off button pressed.");
|
||||
lockState = LOCK_OFF_PRESSED;
|
||||
}
|
||||
break;
|
||||
case LOCK_OFF_PRESSED:
|
||||
if (digitalRead(OFF_BUTTON_PIN) == BUTTON_OPEN) {
|
||||
if (digitalRead(RED_BUTTON_PIN) == BUTTON_OPEN) {
|
||||
if (LOGGING) Serial.println("[INFO] Turning machine off.");
|
||||
lockState = LOCK_OFF;
|
||||
}
|
||||
|
@ -229,7 +229,7 @@ void processCommState()
|
|||
if (LOGGING) Serial.println(payload);
|
||||
String action = deserializeJson(payload);
|
||||
|
||||
if (action == "arm" && lockState == LOCK_OFF && digitalRead(ON_BUTTON_PIN) == BUTTON_OPEN) {
|
||||
if (action == "arm" && lockState == LOCK_OFF && digitalRead(GREEN_BUTTON_PIN) == BUTTON_OPEN) {
|
||||
lockState = LOCK_ARMED;
|
||||
} else if (action == "disarm" && lockState == LOCK_ARMED) {
|
||||
lockState = LOCK_OFF;
|
||||
|
|
Loading…
Reference in New Issue
Block a user