Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. // purpose of this project is to communicate with my girlfriend "hey, I fed the dog" on days that I leave for work
  2. // before she wakes up (or vice-versa)
  3.  
  4. // A red led indicates that the dog has not been fed within the feedMeDelay (8 hours, or whatever)
  5. // A green led indicates that one of us has fed the dog within that time
  6.  
  7. // A pushbutton is present to reset the timer, when one of us feeds the dog
  8.  
  9. unsigned long timeSinceFed;
  10. //feedMeDelay is time from the button being pressed
  11. //until the green LED turns off and red LED turns on
  12. unsigned long feedMeDelay = 10*1000;
  13. //green LED, indicating dog has been fed on pin 4
  14. //red LED, indicating dog has not been fed in more than feedMeDelay on pin 2
  15. //Pushbutton on pin 7
  16. const int happyDog = 3;
  17. const int hungryDog = 2;
  18. const int fedButton = 4;
  19.  
  20. int buttonState = 0;
  21.  
  22.  
  23. void setup() {
  24. // dog is initally hungry on poweron, if he's been fed we push button
  25. Serial.begin(9600);
  26. pinMode(happyDog, OUTPUT);
  27. pinMode(hungryDog, OUTPUT);
  28. pinMode(fedButton, INPUT_PULLUP);
  29. digitalWrite(happyDog, LOW);
  30. digitalWrite(hungryDog, HIGH);
  31. }
  32.  
  33. void loop()
  34. {
  35. //get the time at the start of this loop()
  36. unsigned long currentMillis = millis();
  37.  
  38. // check the button
  39. if (digitalRead(fedButton) == LOW)
  40. {
  41. // Button was pressed
  42. // Dog was fed, update timeSinceFed to current millis
  43. unsigned long timeSinceFed = currentMillis;
  44. //turn on Green LED
  45.  
  46.  
  47.  
  48. if ((currentMillis-timeSinceFed)>=feedMeDelay)
  49. //dog needs to be fed
  50. {
  51. digitalWrite(happyDog, LOW);
  52. digitalWrite(hungryDog, HIGH);
  53. }
  54. else
  55. {
  56. digitalWrite(happyDog, HIGH);
  57. digitalWrite(hungryDog, LOW);
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement