Advertisement
iyera20

Dice Prototype

Jun 10th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. /*
  2. * Atiriya Iyer
  3. * Dice Prototype
  4. * Version 1
  5. */
  6. const int pinLED1= 2;
  7. const int pinLED2= 4;
  8. const int pinLED3= 6;
  9. const int pinButton= 5;
  10. boolean buttonPressed = 0;
  11. boolean LEDon= 0;
  12. boolean previousButton=0;
  13. void setup()
  14. {
  15. // put your setup code here, to run once:
  16. pinMode (pinLED1, OUTPUT);
  17. pinMode (pinLED2, OUTPUT);
  18. pinMode (pinLED3, OUTPUT);
  19. pinMode (pinButton, INPUT);
  20.  
  21. Serial.begin(9600);
  22.  
  23. digitalWrite(pinLED1, HIGH);
  24. digitalWrite(pinLED2, HIGH);
  25. digitalWrite(pinLED3, HIGH);
  26. delay(50);
  27. digitalWrite(pinLED1, LOW);
  28. digitalWrite(pinLED2, LOW);
  29. digitalWrite(pinLED3, LOW);
  30. }
  31.  
  32. void loop()
  33. {
  34. // put your main code here, to run repeatedly:
  35.  
  36. buttonPressed= digitalRead(pinButton);
  37. //Serial.print (buttonPressed);
  38. buttonPressed = debounce(previousButton);
  39.  
  40. if (previousButton== LOW && buttonPressed== HIGH)
  41. {
  42. LEDon =! LEDon;
  43. Serial.print(LEDon);
  44. }
  45. digitalWrite(pinLED1, LEDon);
  46. digitalWrite(pinLED2, LEDon);
  47. digitalWrite(pinLED3, LEDon);
  48.  
  49. previousButton= buttonPressed;
  50. }
  51.  
  52.  
  53. boolean debounce(boolean last)
  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