Created
March 18, 2016 07:01
-
-
Save zamfi/64a3457be13e1c6b96c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int numPins = 12; | |
const int pins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; | |
const int motionSensePin = A0; | |
void setup() { | |
for (int i = 0; i < numPins; ++i) { | |
pinMode(pins[i], OUTPUT); | |
} | |
pinMode(motionSensePin, INPUT); | |
} | |
int litPin = 0; | |
unsigned long lastSecond = 0; | |
boolean systemOn = false; | |
unsigned long lastMotionDetected = 0; | |
void startClock() { | |
systemOn = true; | |
lastSecond = millis(); | |
litPin = 0; | |
digitalWrite(pins[0], HIGH); | |
for (int i = 1; i < numPins; ++i) { | |
digitalWrite(pins[i], LOW); | |
} | |
} | |
void loop() { | |
if (digitalRead(motionSensePin) == LOW) { | |
lastMotionDetected = millis(); | |
if (! systemOn) { | |
startClock(); | |
} | |
} | |
if (millis() < lastMotionDetected || | |
millis() - lastMotionDetected > 10 * 60 * 1000) { // 10 min * 60 s/min * 1000 ms/s | |
systemOn = false; | |
} | |
if (systemOn) { | |
if (millis() < lastSecond || millis() - lastSecond > 1000) { | |
digitalWrite(pins[litPin], LOW); | |
litPin = (litPin + 1) % numPins; | |
digitalWrite(pins[litPin], HIGH); | |
lastSecond = millis(); | |
} | |
} else { | |
for (int i = 0; i < numPins; ++i) { | |
digitalWrite(pins[i], LOW); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment