const int button =10; // GPIO 10 for the button const int led =11; // GPIO 11 for the LED int ledflag =0; // LED status flag int brightness = 0; // how bright the LED is int fadeAmount = 5; // how many points to fade the LED by void setup() { pinMode(button,INPUT); // define button as an input pinMode(led,OUTPUT); // define LED as an output digitalWrite(led,LOW); // turn output off just in case } void loop() { if (digitalRead(button)==HIGH){ // if button is pressed if (ledflag==0) { // and the status flag is LOW ledflag=1; // make status flag HIGH // set the brightness of pin 9: analogWrite(led, brightness); // change the brightness for next time through the loop: brightness = brightness + fadeAmount; // reverse the direction of the fading at the ends of the fade: if (brightness <= 0 || brightness >= 255) { fadeAmount = -fadeAmount; } // wait for 60 milliseconds to see the dimming effect delay(60); //digitalWrite(led,HIGH); // and turn on the LED } else { ledflag=0; // make status flag LOW //digitalWrite(led,LOW); // and turn off the LED } } //delay(1000); // wait a sec for the // hardware to stabilize } // begin again