Advertisement
manvi_m

LED stays on until button is pressed again

Jun 7th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. /*
  2. * Manvi Mittal
  3. * Version 2
  4. * Leaning digital imputs
  5. */
  6.  
  7. const int pinLed = 7;
  8. const int pinButton = 2;
  9. int readValue = 0;
  10. boolean lightOn = 0;
  11.  
  12. void setup()
  13. {
  14. // put your setup code here, to run once:
  15. pinMode (pinButton, INPUT);
  16. pinMode (pinLed, OUTPUT);
  17.  
  18. Serial.begin (9600);
  19.  
  20. digitalWrite (pinLed, HIGH);
  21. delay (50);
  22. digitalWrite (pinLed, LOW);
  23.  
  24. }
  25.  
  26. void loop()
  27. {
  28. // put your main code here, to run repeatedly:
  29. readValue = digitalRead (pinButton);
  30.  
  31. if(readValue == 1)
  32. {
  33. lightOn = !lightOn;
  34. digitalWrite (pinLed, lightOn);
  35. }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement