Added basic handling of door sensor code
This commit is contained in:
parent
d07ce7d66c
commit
77615d691a
|
@ -33,6 +33,7 @@ Adafruit_NeoPixel neopix = Adafruit_NeoPixel(NEO_PIX_NUM, PIN_NEO, NEO_GRB + NEO
|
||||||
uint8_t rgb[3]; // index 0 = red / index 1 = green / index 2 = blue
|
uint8_t rgb[3]; // index 0 = red / index 1 = green / index 2 = blue
|
||||||
bool white = false;
|
bool white = false;
|
||||||
bool max_found = false;
|
bool max_found = false;
|
||||||
|
bool door_open = false;
|
||||||
|
|
||||||
// Various function definitions
|
// Various function definitions
|
||||||
void hsvToRgb(int h, double s, double v); // See end of file for implementation
|
void hsvToRgb(int h, double s, double v); // See end of file for implementation
|
||||||
|
@ -97,6 +98,7 @@ void loop() {
|
||||||
raw_color = analogRead(POT_COLOR); // Color (0-1024)
|
raw_color = analogRead(POT_COLOR); // Color (0-1024)
|
||||||
always_on = (digitalRead(PIN_ALWAYS_ON) == HIGH); // Toggle button pressed == ALWAYS ON
|
always_on = (digitalRead(PIN_ALWAYS_ON) == HIGH); // Toggle button pressed == ALWAYS ON
|
||||||
white = (digitalRead(PIN_WHITE) == HIGH); // Shorted pin to enable white color for LEDs
|
white = (digitalRead(PIN_WHITE) == HIGH); // Shorted pin to enable white color for LEDs
|
||||||
|
door_open = (digitalRead(PIN_DOOR == HIGH)); // SparkFun door sensor is indicating door is open (NO for door closed state)
|
||||||
|
|
||||||
// Set RGB array to values as appropriate
|
// Set RGB array to values as appropriate
|
||||||
if (white) {
|
if (white) {
|
||||||
|
@ -142,12 +144,14 @@ void loop() {
|
||||||
Serial.println(rgb[2]);
|
Serial.println(rgb[2]);
|
||||||
Serial.print("Always on: ");
|
Serial.print("Always on: ");
|
||||||
Serial.println(always_on);
|
Serial.println(always_on);
|
||||||
|
Serial.print("Door sensor: ");
|
||||||
|
Serial.println(door_open);
|
||||||
Serial.println("----------");
|
Serial.println("----------");
|
||||||
delay(250);
|
delay(250);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sleep mode enabled
|
// Sleep mode enabled
|
||||||
if (USE_SLEEP && !always_on) { // Don't enable sleep if always on toggle is set
|
if (USE_SLEEP && !always_on && !door_open) { // Don't enable sleep if always on toggle is set
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Serial.println("SLEEPING!");
|
Serial.println("SLEEPING!");
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue