Advertisement
Guest User

Count Program

a guest
Dec 5th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. // counter button w/ different outcomes with different number of button presses
  2. // Nikitha Thoduguli
  3. // 12.05.19
  4. // Ver 3
  5.  
  6. int ledPin=8;
  7. int ledPin2=10;
  8. int buttonPin=2;
  9. int readValue;
  10. int count = 0;
  11.  
  12.  
  13. void setup() {
  14. // put your setup code here, to run once:
  15.  
  16. pinMode (buttonPin, INPUT);
  17. pinMode (ledPin, OUTPUT);
  18. pinMode (ledPin2, OUTPUT);
  19. Serial.begin (9600);
  20. digitalWrite (ledPin, HIGH);
  21. digitalWrite (ledPin2, HIGH);
  22. delay (100);
  23. digitalWrite (ledPin2, LOW);
  24. digitalWrite (ledPin, LOW);
  25.  
  26. Serial.println (readValue);
  27. delay (100);
  28. }
  29.  
  30. void loop() {
  31. readValue = digitalRead (buttonPin);
  32. delay(100);
  33. if (readValue ==1)
  34.  
  35. {
  36. count ++;
  37. Serial.println (count);
  38. }
  39.  
  40.  
  41. if (count == 1)
  42. {
  43. digitalWrite (ledPin, HIGH);
  44. digitalWrite (ledPin2, LOW);
  45. }
  46. if (count ==2 )
  47. {
  48. digitalWrite (ledPin, LOW);
  49. digitalWrite (ledPin2, HIGH);
  50.  
  51. }
  52.  
  53. if (count ==3)
  54. {
  55. digitalWrite (ledPin, HIGH);
  56. digitalWrite (ledPin2, HIGH);
  57.  
  58. }
  59.  
  60. if (count ==4)
  61. {
  62. digitalWrite (ledPin, LOW);
  63. digitalWrite (ledPin2, LOW);
  64. count = 0;
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement