Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1.  
  2. /* Alex Witheiler
  3. * DC Moter
  4. * 11/30/16
  5. */
  6. const int butpin=2;
  7. const int motor=9;
  8. int readval=0;
  9. int lastval=0;
  10. bool lastbut=false;
  11. bool currentbut=false;
  12. bool motoron=false;
  13.  
  14. void setup()
  15. {
  16. pinMode (butpin, INPUT);
  17. pinMode (motor, OUTPUT);
  18. Serial.begin(9600);
  19.  
  20. }
  21.  
  22. boolean debounce (boolean last)
  23. {
  24. boolean current = digitalRead (butpin);
  25. if (last !=current);
  26. {
  27. delay (5);
  28. current = digitalRead (butpin);
  29. }
  30. return current;
  31. }
  32.  
  33. void loop()
  34. {
  35. currentbut=debounce (lastbut);
  36. if (lastbut ==LOW && currentbut==HIGH)
  37. {
  38. motoron= !motoron;
  39.  
  40. }
  41. digitalWrite (motor, motoron);
  42.  
  43. lastbut = currentbut;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement