arfachowdhary

boolin

Mar 22nd, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. const int LedPin = 6;
  2. const int ButtonPin = 12;
  3. int counter = 0;
  4. bool ReadVal = 0;
  5. bool LastReadVal = 0;
  6. void setup()
  7.  
  8. {
  9. pinMode (LedPin, OUTPUT);
  10. pinMode (ButtonPin, INPUT) ;
  11. Serial.begin(9600) ;
  12. }
  13. boolean debounce(boolean last)
  14. {
  15. boolean current = digitalRead(ButtonPin);
  16. if (last != current)
  17. {
  18. delay(5);
  19. current = digitalRead(ButtonPin);
  20. }
  21. return current;
  22. }
  23.  
  24. void loop()
  25. {
  26. ReadVal = digitalRead(ButtonPin) ;
  27. Serial.println(ReadVal) ;
  28. if (LastReadVal == LOW && ReadVal == HIGH && counter == 0)
  29. {
  30. for (int i = 0; i < 200; i++)
  31. {
  32. analogWrite(LedPin, i);
  33. delay(20);
  34. ReadVal = digitalRead(ButtonPin);
  35. if (ReadVal == 1)
  36. {
  37. i = 200;
  38. }
  39. }
  40. counter = 1;
  41. }
  42. else if (ReadVal == 1 && counter == 1)
  43. {
  44. for (int i = 200; i >= 0; i--)
  45. {
  46. analogWrite (LedPin, i);
  47. delay(20);
  48. }
  49.  
  50. counter = 0;
  51. }
  52. LastReadVal=ReadVal;
  53.  
  54. }
Add Comment
Please, Sign In to add comment