Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // purpose of this project is to communicate with my girlfriend "hey, I fed the dog" on days that I leave for work
- // before she wakes up (or vice-versa)
- // A red led indicates that the dog has not been fed within the feedMeDelay (8 hours, or whatever)
- // A green led indicates that one of us has fed the dog within that time
- // A pushbutton is present to reset the timer, when one of us feeds the dog
- unsigned long timeSinceFed;
- //feedMeDelay is time from the button being pressed
- //until the green LED turns off and red LED turns on
- unsigned long feedMeDelay = 10*1000;
- //green LED, indicating dog has been fed on pin 4
- //red LED, indicating dog has not been fed in more than feedMeDelay on pin 2
- //Pushbutton on pin 7
- const int happyDog = 3;
- const int hungryDog = 2;
- const int fedButton = 4;
- int buttonState = 0;
- void setup() {
- // dog is initally hungry on poweron, if he's been fed we push button
- Serial.begin(9600);
- pinMode(happyDog, OUTPUT);
- pinMode(hungryDog, OUTPUT);
- pinMode(fedButton, INPUT_PULLUP);
- digitalWrite(happyDog, LOW);
- digitalWrite(hungryDog, HIGH);
- }
- void loop()
- {
- //get the time at the start of this loop()
- unsigned long currentMillis = millis();
- // check the button
- if (digitalRead(fedButton) == LOW)
- {
- // Button was pressed
- // Dog was fed, update timeSinceFed to current millis
- unsigned long timeSinceFed = currentMillis;
- //turn on Green LED
- if ((currentMillis-timeSinceFed)>=feedMeDelay)
- //dog needs to be fed
- {
- digitalWrite(happyDog, LOW);
- digitalWrite(hungryDog, HIGH);
- }
- else
- {
- digitalWrite(happyDog, HIGH);
- digitalWrite(hungryDog, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement