Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int motor = 9;
- const int button = 10;
- int ReadValue;
- int count = 0;
- boolean currentButton;
- boolean lastButton;
- boolean flagOn;
- void setup()
- {
- pinMode (motor, OUTPUT);
- Serial.begin (9600);
- }
- boolean debounce (boolean last)
- {
- boolean current = digitalRead (button);
- if (last != current)
- {
- delay (5);
- current = digitalRead (button);
- }
- return current;
- }
- void loop()
- {
- currentButton = debounce (lastButton);
- if (lastButton == LOW && currentButton == HIGH)
- {
- count ++;
- Serial.println (count);
- }
- if (count == 0)
- {
- analogWrite (motor, 0);
- delay (50);
- }
- if (count == 1)
- {
- analogWrite (motor, 100);
- delay (50);
- }
- if (count == 2)
- {
- analogWrite (motor, 150);
- delay (50);
- }
- if (count == 3)
- {
- analogWrite (motor, 200);
- delay (50);
- }
- if (count == 4)
- {
- analogWrite (motor, 250);
- delay (50);
- }
- if (count == 5)
- {
- count =0;
- }
- lastButton = currentButton;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement