Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Alex Witheiler
- * DC Moter
- * 11/30/16
- */
- const int butpin=2;
- const int motor=9;
- int readval=0;
- int lastval=0;
- bool lastbut=false;
- bool currentbut=false;
- bool motoron=false;
- void setup()
- {
- pinMode (butpin, INPUT);
- pinMode (motor, OUTPUT);
- Serial.begin(9600);
- }
- boolean debounce (boolean last)
- {
- boolean current = digitalRead (butpin);
- if (last !=current);
- {
- delay (5);
- current = digitalRead (butpin);
- }
- return current;
- }
- void loop()
- {
- currentbut=debounce (lastbut);
- if (lastbut ==LOW && currentbut==HIGH)
- {
- motoron= !motoron;
- }
- digitalWrite (motor, motoron);
- lastbut = currentbut;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement