/* Hightechrobo learn by Arian */ #define button 4 #define led 3 bool a = false; int lastm = 0 ; int nowm = 0 ; int b = 0 ; void setup() { // put your setup code here, to run once: //pinMode(led,OUTPUT); pinMode(button,INPUT_PULLUP); } void loop() { // put your main code here, to run repeatedly: if(digitalRead(button) == 0 and a == 0){ a = 1; lastm = millis(); b = 255; while(digitalRead(button) == 0){ analogWrite(led,b); nowm = millis(); if(nowm - lastm > 500) { lastm = millis(); b = b - 50 ; } if(b <= 0 ) a = 0 ; } } else if(digitalRead(button) == 0 and a == 1){ a = 0; while(digitalRead(button) == 0){ analogWrite(led,0); } } }