Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int lastMillis = -1;
- int currentMillis = -1;
- int buttonState = -1;
- int buttonLastState = -1;
- int button = 3;
- int led = 4;
- void setup() {
- // put your setup code here, to run once:
- pinMode(button, INPUT_PULLUP);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- buttonState = digitalRead(button);
- currentMillis = millis();
- if(buttonState != buttonLastState){
- if(buttonState == LOW){
- digitalWrite(led, HIGH);
- lastMillis = millis();
- }
- }
- if(currentMillis - lastMillis > 2000){
- digitalWrite(led, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment