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