User:Truongdat120891/enes100/code2

int switchPin = 2; int led1Pin = 3; int led2Pin = 5; int led3Pin = 6;
 * 1) define FADESPEED 5

int val; int val2; int buttonState; int lightMode = 0;

void setup { pinMode(switchPin, INPUT);

pinMode(led1Pin, OUTPUT); pinMode(led2Pin, OUTPUT); pinMode(led3Pin, OUTPUT); Serial.begin(9600); buttonState = digitalRead(switchPin); }

void loop{ int r, g, b; val = digitalRead(switchPin); delay(10); val2 = digitalRead(switchPin); if (val == val2) { if (val != buttonState) { if (val == LOW) { if (lightMode == 0) { lightMode = 1; } else { if (lightMode == 1) { lightMode = 2; } else { if (lightMode == 2) { lightMode = 3; } else { if (lightMode == 3) { lightMode = 0; }			}         }        }      }    }    buttonState = val; }

if (lightMode == 0) { digitalWrite(led1Pin, LOW); digitalWrite(led2Pin, LOW); digitalWrite(led3Pin, LOW); }

if (lightMode == 1) { delay(100); digitalWrite(led1Pin, LOW); digitalWrite(led2Pin, HIGH); digitalWrite(led3Pin, HIGH); delay(100); digitalWrite(led1Pin, LOW); digitalWrite(led2Pin, HIGH); digitalWrite(led3Pin, LOW); delay(100); digitalWrite(led1Pin, HIGH); digitalWrite(led2Pin, HIGH); digitalWrite(led3Pin, LOW); delay(100); digitalWrite(led1Pin, HIGH); digitalWrite(led2Pin, LOW); digitalWrite(led3Pin, LOW); delay(100); digitalWrite(led1Pin, LOW); digitalWrite(led2Pin, LOW); digitalWrite(led3Pin, HIGH); delay(100); digitalWrite(led1Pin, HIGH); digitalWrite(led2Pin, LOW); digitalWrite(led3Pin, HIGH); }

if (lightMode == 2)

{    delay(25); digitalWrite(led1Pin, LOW); digitalWrite(led2Pin, HIGH); digitalWrite(led3Pin, HIGH); delay(25); digitalWrite(led1Pin, LOW); digitalWrite(led2Pin, HIGH); digitalWrite(led3Pin, LOW); delay(25); digitalWrite(led1Pin, HIGH); digitalWrite(led2Pin, HIGH); digitalWrite(led3Pin, LOW); delay(25); digitalWrite(led1Pin, HIGH); digitalWrite(led2Pin, LOW); digitalWrite(led3Pin, LOW); delay(25); digitalWrite(led1Pin, LOW); digitalWrite(led2Pin, LOW); digitalWrite(led3Pin, HIGH); delay(25); digitalWrite(led1Pin, HIGH); digitalWrite(led2Pin, LOW); digitalWrite(led3Pin, HIGH); } if (lightMode == 3) { delay(100); digitalWrite(led1Pin, LOW); digitalWrite(led2Pin, HIGH); digitalWrite(led3Pin, HIGH); delay(100); digitalWrite(led1Pin, LOW); digitalWrite(led2Pin, HIGH); digitalWrite(led3Pin, LOW); delay(100); digitalWrite(led1Pin, HIGH); digitalWrite(led2Pin, HIGH); digitalWrite(led3Pin, LOW); delay(100); digitalWrite(led1Pin, HIGH); digitalWrite(led2Pin, LOW); digitalWrite(led3Pin, LOW); delay(100); digitalWrite(led1Pin, LOW); digitalWrite(led2Pin, LOW); digitalWrite(led3Pin, HIGH); delay(100); digitalWrite(led1Pin, HIGH); digitalWrite(led2Pin, LOW); digitalWrite(led3Pin, HIGH); }  }