Skip to content

Commit

Permalink
bug corrections - v2 complete
Browse files Browse the repository at this point in the history
  • Loading branch information
pierreca committed Sep 2, 2014
1 parent 61a269a commit 957c67d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
1 change: 1 addition & 0 deletions Case/Casing.scad
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,5 @@ color("red") ring_mounting(0,0,0);
//projection() difference() {
// back_plate(0,0,-33);
// mounting_hardware(0,0,0);
// translate([55,-30,-13]) rotate([0,180,0]) waterproof_pushbutton(0,0,0,4);
//}
33 changes: 15 additions & 18 deletions LightClock.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

#define TRANSITION_DELAY 300

#define AWAKE_TIME_SECONDS 3600
#define AWAKE_TIME_SECONDS 1800

RTC_DS1307 rtc;

Expand Down Expand Up @@ -73,11 +73,6 @@ DateTime wakeUpTime;
bool wakeUp = false;
bool pirEnabled = true;

long lastDebounceTime = 0;
long debounceDelay = 50;
int pirOverrideButtonState;
int lastPirOverrideButtonState = HIGH;

void setup()
{
Serial.begin(115200);
Expand Down Expand Up @@ -133,21 +128,23 @@ void setup()

void loop()
{
// Debounce the PIR Override button (based on http://arduino.cc/en/Tutorial/Debounce)
int currentPirOverrideButtonState = digitalRead(PIR_OVERRIDE_BUTTON_PIN);
if (currentPirOverrideButtonState != lastPirOverrideButtonState)
{
lastDebounceTime = millis();
}

if ((millis() - lastDebounceTime) > debounceDelay
&& currentPirOverrideButtonState != lastPirOverrideButtonState)
if (digitalRead(PIR_OVERRIDE_BUTTON_PIN) == LOW)
{
pirEnabled = !pirEnabled;
digitalWrite(PIR_OVERRIDE_LED, pirEnabled);

if (clockStateMachine.isInState(Sleeping)) {
wakeUp = true;
}
else
{
wakeUp = false;
clockStateMachine.transitionTo(Sleeping);
}

delay(300);
}

lastPirOverrideButtonState = currentPirOverrideButtonState;
digitalWrite(PIR_OVERRIDE_LED, pirEnabled);

uint8_t buttons = lcd.readButtons();

Expand All @@ -171,6 +168,7 @@ void loop()

if (clockStateMachine.isInState(Sleeping) && wakeUp)
{
wakeUpTime = rtc.now();
clockStateMachine.transitionTo(ShowTime);
}
else if (clockStateMachine.isInState(ShowTime))
Expand Down Expand Up @@ -662,7 +660,6 @@ void setSleepingUpdate()
{
if (pirEnabled && digitalRead(PIR_PIN) == HIGH)
{
wakeUpTime = rtc.now();
wakeUp = true;
}
}
Expand Down

0 comments on commit 957c67d

Please sign in to comment.