Guest User

Untitled

a guest
Jul 18th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. }
  2.  
  3. if (digitalRead(buttonPin2) == HIGH) { // check if buttonPin2 was pressed (be sure to use a resistor?)
  4. {digitalWrite(ledPin2, LOW); // turn ledPin2 on
  5. ledPin2_status = 1; // 1 = on, set ledPin2_status to 1
  6.  
  7. }
  8.  
  9. // set pins
  10. const int buttonPin1 = 2; // Pin1's pushbutton
  11. const int buttonPin2 = 4; // Pin2's pushbutton
  12. const int buttonPin3 = 6; // Pin3's pushbutton
  13. const int buttonPin4 = 8; // Pin4's pushbutton
  14. const int ledPin1 = 3; // Pin1's LED
  15. const int ledPin2 = 5; // Pin2's LED
  16. const int ledPin3 = 7; // Pin3's LED
  17. const int ledPin4 = 9; // Pin4's LED
  18.  
  19. // set variables
  20. int ledPin1_status = 0;
  21. int ledPin2_status = 0;
  22. int ledPin3_status = 0;
  23. int ledPin4_status = 0;
  24.  
  25. void setup() { //initialize pins
  26. pinMode(buttonPin1, INPUT); // set PINn as INPUT
  27. pinMode(buttonPin2, INPUT);
  28. pinMode(buttonPin3, INPUT);
  29. pinMode(buttonPin4, INPUT);
  30. pinMode(ledPin1, OUTPUT); // set LEDn as OUTPUT
  31. pinMode(ledPin2, OUTPUT);
  32. pinMode(ledPin3, OUTPUT);
  33. pinMode(ledPin4, OUTPUT);
  34. }
  35.  
  36. // the following variables are unsigned longs because the time, measured in
  37. // milliseconds, will quickly become a bigger number than can be stored in an int.
  38. unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
  39. unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
  40.  
  41. void loop() {
  42. if (digitalRead(buttonPin1) == HIGH) { // check if buttonPin1 was pressed (be sure to use a resistor?)
  43. if (ledPin1_status == 0) { // check if ledPin1 was not already pressed
  44. digitalWrite(ledPin1, HIGH); // turn ledPin1 on
  45. ledPin1_status = 1; // 1 = on, set ledPin1_status to 1
  46.  
  47. }
  48. else {
  49. digitalWrite(ledPin1, LOW); // turn ledPin1 off
  50. ledPin1_status = 0; // 0 = off, set Pin1_status to 0
  51. digitalWrite(ledPin2, LOW); // turn ledPin2 off
  52. ledPin2_status = 0; // 0 = off, set Pin2_status to 0
  53. digitalWrite(ledPin3, LOW); // turn ledPin3 off
  54. ledPin3_status = 0; // 0 = off, set Pin2_status to 0
  55. digitalWrite(ledPin4, LOW); // turn ledPin4 off
  56. ledPin3_status = 0; // 0 = off, set Pin2_status to 0
  57. }
  58. }
  59.  
  60. if (digitalRead(buttonPin2) == HIGH) { // check if buttonPin2 was pressed (be sure to use a resistor?)
  61. {digitalWrite(ledPin2, HIGH); // turn ledPin2 on
  62. ledPin2_status = 1; // 1 = on, set ledPin2_status to 1
  63.  
  64. }
  65.  
  66. }
  67.  
  68. if (digitalRead(buttonPin2) == HIGH) { // check if buttonPin2 was pressed (be sure to use a resistor?)
  69. {digitalWrite(ledPin2, LOW); // turn ledPin2 on
  70. ledPin2_status = 1; // 1 = on, set ledPin2_status to 1
  71.  
  72. }
  73.  
  74. }
  75.  
  76. if (digitalRead(buttonPin3) == HIGH) { // check if buttonPin3 was pressed (be sure to use a resistor?)
  77. {digitalWrite(ledPin3, HIGH); // turn ledPin3 on
  78. ledPin3_status = 1; // 1 = on, set ledPin3_status to 1
  79.  
  80. }
  81.  
  82. }
  83.  
  84. if (digitalRead(buttonPin3) == HIGH) { // check if buttonPin2 was pressed (be sure to use a resistor?)
  85. {digitalWrite(ledPin3, LOW); // turn ledPin3 on
  86. ledPin2_status = 1; // 1 = on, set ledPin2_status to 1
  87.  
  88. }
  89.  
  90. }
  91.  
  92. if (digitalRead(buttonPin4) == HIGH) { // check if buttonPin2 was pressed (be sure to use a resistor?)
  93. {digitalWrite(ledPin4, HIGH); // turn ledPin4 on
  94. ledPin2_status = 1; // 1 = on, set ledPin2_status to 1
  95.  
  96. }
  97. }
  98.  
  99. if (digitalRead(buttonPin4) == HIGH) { // check if buttonPin2 was pressed (be sure to use a resistor?)
  100. {digitalWrite(ledPin4, LOW); // turn ledPin4 on
  101. ledPin2_status = 1; // 1 = on, set ledPin2_status to 1
  102.  
  103. }
  104.  
  105.  
  106.  
  107. }
Add Comment
Please, Sign In to add comment