const int buttonPin = 3; // the number of the pushbutton pin const int ledPin1 = 0; // the number of the LED pin1 const int ledPin2 = 1; // the number of the LED pin2 const int ledPin3 = 6; // the number of the LED pin3 // variables will change: int buttonState = 0; // variable for reading the pushbutton status int buttonCount = 0; int delay_interval = 0; void setup() { Serial.begin(115200); // initialize the LED pin1 as an output: pinMode(ledPin1, OUTPUT); // initialize the LED pin2 as an output: pinMode(ledPin2, OUTPUT); // initialize the LED pin3 as an output: pinMode(ledPin3, OUTPUT); // initialize the button pin as an input pullup: pinMode(buttonPin, INPUT_PULLUP); } void loop() { // read the state of the pushbutton value: buttonState = digitalRead(buttonPin); Serial.print("buttonState: "); Serial.println(buttonState); Serial.print("buttonCount: "); Serial.println(buttonCount); if (buttonState == LOW) { buttonCount+= 1; delay(500); if (buttonCount > 3) { buttonCount = 0; } } if (buttonCount == 0) { digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, LOW); } else if (buttonCount == 1) { // fade in from min to max in increments of 5 points: for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) { // sets the value (range from 0 to 255): analogWrite(ledPin1, fadeValue); // wait for 30 milliseconds to see the dimming effect delay(30); } // fade out from max to min in increments of 5 points: for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) { // sets the value (range from 0 to 255): analogWrite(ledPin1, fadeValue); // wait for 30 milliseconds to see the dimming effect delay(30); } } else if (buttonCount == 2) { // fade in from min to max in increments of 5 points: for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) { // sets the value (range from 0 to 255): analogWrite(ledPin2, fadeValue); // wait for 30 milliseconds to see the dimming effect delay(30); } // fade out from max to min in increments of 5 points: for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) { // sets the value (range from 0 to 255): analogWrite(ledPin2, fadeValue); // wait for 30 milliseconds to see the dimming effect delay(30); } } else if (buttonCount == 3) { // fade in from min to max in increments of 5 points: for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) { // sets the value (range from 0 to 255): analogWrite(ledPin3, fadeValue); // wait for 30 milliseconds to see the dimming effect delay(30); } // fade out from max to min in increments of 5 points: for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) { // sets the value (range from 0 to 255): analogWrite(ledPin3, fadeValue); // wait for 30 milliseconds to see the dimming effect delay(30); } } }