Advertisement
inagantid20

Dice LED Version 1

Jun 12th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. /*
  2. * Divya Inaganti
  3. * June 9, 2017
  4. * LED Dice Prototype version 2
  5. */
  6. const int pinLed1 = 2;
  7. const int pinLed2 = 7;
  8. const int pinLed3 = 4;
  9. const int pinButton = 8;
  10. boolean buttonDown = 0;
  11. boolean ledOn = 0;
  12. boolean lastButton = 0;
  13. void setup() {
  14. // put your setup code here, to run once:
  15. pinMode (pinLed1, OUTPUT);
  16. pinMode (pinLed2, OUTPUT);
  17. pinMode (pinLed3, OUTPUT);
  18. pinMode (pinButton, INPUT);
  19.  
  20. Serial. begin (9600);
  21. digitalWrite (pinLed1, HIGH);
  22. digitalWrite (pinLed2, HIGH);
  23. digitalWrite (pinLed3, HIGH);
  24. delay(500);
  25. digitalWrite (pinLed1, LOW);
  26. digitalWrite (pinLed2, LOW);
  27. digitalWrite (pinLed3, LOW);
  28.  
  29. }
  30.  
  31. void loop() {
  32. // put your main code here, to run repeatedly:
  33. buttonDown = digitalRead(pinButton);
  34. //Serial.print (buttonDown);
  35.  
  36.  
  37. buttonDown = debounce(lastButton); // will go and read the Button
  38.  
  39. if (lastButton == LOW && buttonDown == HIGH) // Checks if the button has been pressed
  40. {
  41. ledOn = ! ledOn;
  42. }
  43. // else if(lastButton == HIGH && buttonDown == LOW)
  44. //{
  45. //Serial.print (0);
  46. //}
  47. digitalWrite(pinLed1, ledOn);
  48. lastButton = buttonDown;
  49.  
  50. }
  51.  
  52. boolean debounce(boolean last)
  53.  
  54. {
  55. boolean current = digitalRead(pinButton);
  56. if (last != current)
  57. {
  58. delay(5);
  59. current = digitalRead(pinButton);
  60. }
  61. return current;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement