manvi_m

Light of LED increases as button is held down

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