Advertisement
octo_cat

Untitled

Jun 10th, 2020
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. bool lastButtonState;
  2. const int buttonPin = 2;
  3. const int buttonPin1 = 3;
  4. const int ledPin0 = 13; //green light
  5. const int ledPin1 = 12; //yellow light
  6. const int ledPin2 = 11; //red light
  7. int buttonState = 0;
  8. int buttonState1 = 0;
  9. int startPressed = 0;
  10. int endPressed = 0;
  11. int holdTime = 0;
  12. int idleTime = 0;
  13. int count = 0;
  14.  
  15. void setup() {
  16. Serial.begin(9600);
  17. pinMode(ledPin0, OUTPUT);
  18. pinMode(ledPin1, OUTPUT);
  19. pinMode(ledPin2, OUTPUT);
  20. pinMode(buttonPin, INPUT);
  21. pinMode(buttonPin1, INPUT);
  22. }
  23. void loop(){
  24. buttonState = digitalRead(buttonPin);
  25. if (buttonState == HIGH && lastButtonState == LOW) {
  26. lastButtonState = buttonState;
  27. count++;
  28. if (count >= 19) {
  29. count = 0;
  30. }
  31. }
  32. else {
  33. lastButtonState = buttonState;
  34. digitalWrite(ledPin0, LOW);
  35. digitalWrite(ledPin1, LOW);
  36. digitalWrite(ledPin2, LOW);
  37. }
  38.  
  39.  
  40. if (count == 1) {
  41. digitalWrite(ledPin0, HIGH);
  42. digitalWrite(ledPin1, HIGH);
  43. digitalWrite(ledPin2, HIGH);
  44. }
  45. if (count == 2) {
  46. digitalWrite(ledPin0, HIGH);
  47. digitalWrite(ledPin1, HIGH);
  48. digitalWrite(ledPin2, HIGH);
  49. } if (count == 3) {
  50. digitalWrite(ledPin0, HIGH);
  51. digitalWrite(ledPin1, HIGH);
  52. digitalWrite(ledPin2, HIGH);
  53. } if (count == 4) {
  54. digitalWrite(ledPin0, HIGH);
  55. digitalWrite(ledPin1, HIGH);
  56. digitalWrite(ledPin2, HIGH);
  57. } if (count == 5) {
  58. digitalWrite(ledPin0, HIGH);
  59. digitalWrite(ledPin1, HIGH);
  60. digitalWrite(ledPin2, HIGH);
  61. } if (count == 6) {
  62. digitalWrite(ledPin0, HIGH);
  63. digitalWrite(ledPin1, HIGH);
  64. digitalWrite(ledPin2, HIGH);
  65. }
  66. else {
  67. digitalWrite(ledPin0, LOW);
  68. digitalWrite(ledPin1, LOW);
  69. digitalWrite(ledPin2, LOW);
  70. }
  71.  
  72.  
  73. if (count == 7) {
  74. digitalWrite(ledPin1, HIGH);
  75. digitalWrite(ledPin2, HIGH);
  76. }
  77. if (count == 8) {
  78. digitalWrite(ledPin1, HIGH);
  79. digitalWrite(ledPin2, HIGH);
  80. } if (count == 9) {
  81. digitalWrite(ledPin1, HIGH);
  82. digitalWrite(ledPin2, HIGH);
  83. } if (count == 10) {
  84. digitalWrite(ledPin1, HIGH);
  85. digitalWrite(ledPin2, HIGH);
  86. } if (count == 11) {
  87. digitalWrite(ledPin1, HIGH);
  88. digitalWrite(ledPin2, HIGH);
  89. } if (count == 12) {
  90. digitalWrite(ledPin1, HIGH);
  91. digitalWrite(ledPin2, HIGH);
  92. }
  93. else {
  94. digitalWrite(ledPin1, LOW);
  95. digitalWrite(ledPin2, LOW);
  96. }
  97.  
  98.  
  99. if (count == 13) {
  100. digitalWrite(ledPin2, HIGH);
  101. }
  102. if (count == 14) {
  103. digitalWrite(ledPin2, HIGH);
  104. } if (count == 15) {
  105. digitalWrite(ledPin2, HIGH);
  106. } if (count == 16) {
  107. digitalWrite(ledPin2, HIGH);
  108. } if (count == 17) {
  109. digitalWrite(ledPin2, HIGH);
  110. } if (count == 18) {
  111. digitalWrite(ledPin2, HIGH);
  112. }
  113. else {
  114. digitalWrite(ledPin2, LOW);
  115.  
  116. }
  117. }
  118. buttonState1 = digitalRead(buttonPin1);
  119.  
  120. if (buttonState1 != lastButtonState) {
  121. updateState();
  122. }
  123.  
  124. lastButtonState = button State1;
  125. }
  126. void updateState() {
  127. if (buttonState1 == HIGH) {
  128. startPressed = millis();
  129. idleTime = startPressed - endPressed;
  130. } else {
  131. endPressed = millis();
  132. holdTime = endPressed - startPressed;
  133.  
  134. if (holdTime >= 1000) {
  135. Serial.println("UwU");
  136. }
  137.  
  138. }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement