Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int LedPin = 6;
- const int ButtonPin = 12;
- int counter = 0;
- bool ReadVal = 0;
- bool LastReadVal = 0;
- void setup()
- {
- pinMode (LedPin, OUTPUT);
- pinMode (ButtonPin, INPUT) ;
- Serial.begin(9600) ;
- }
- boolean debounce(boolean last)
- {
- boolean current = digitalRead(ButtonPin);
- if (last != current)
- {
- delay(5);
- current = digitalRead(ButtonPin);
- }
- return current;
- }
- void loop()
- {
- ReadVal = digitalRead(ButtonPin) ;
- Serial.println(ReadVal) ;
- if (LastReadVal == LOW && ReadVal == HIGH && counter == 0)
- {
- for (int i = 0; i < 200; i++)
- {
- analogWrite(LedPin, i);
- delay(20);
- ReadVal = digitalRead(ButtonPin);
- if (ReadVal == 1)
- {
- i = 200;
- }
- }
- counter = 1;
- }
- else if (ReadVal == 1 && counter == 1)
- {
- for (int i = 200; i >= 0; i--)
- {
- analogWrite (LedPin, i);
- delay(20);
- }
- counter = 0;
- }
- LastReadVal=ReadVal;
- }
Add Comment
Please, Sign In to add comment