User:Truongdat120891/enes100/codeing

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(500);

{ for (r = 0; r < 256; r++) { analogWrite(led1Pin, r); delay(FADESPEED); }

for (b = 255; b > 0; b--) { analogWrite(led2Pin, b); delay(FADESPEED); }

for (g = 0; g < 256; g++) { analogWrite(led3Pin, g); delay(FADESPEED); }

for (r = 255; r > 0; r--) { analogWrite(led1Pin, r); delay(FADESPEED); }

for (b = 0; b < 256; b++) { analogWrite(led2Pin, b); delay(FADESPEED); }

for (g = 255; g > 0; g--) { analogWrite(led3Pin, g); delay(FADESPEED); } }

if (lightMode == 2)

{    delay(500); digitalWrite(led1Pin, LOW); digitalWrite(led2Pin, HIGH); digitalWrite(led3Pin, HIGH); delay(500); digitalWrite(led1Pin, LOW); digitalWrite(led2Pin, HIGH); digitalWrite(led3Pin, LOW); delay(500); digitalWrite(led1Pin, HIGH); digitalWrite(led2Pin, HIGH); digitalWrite(led3Pin, LOW); delay(500); digitalWrite(led1Pin, HIGH); digitalWrite(led2Pin, LOW); digitalWrite(led3Pin, LOW); delay(500); digitalWrite(led1Pin, LOW); digitalWrite(led2Pin, LOW); digitalWrite(led3Pin, HIGH); delay(500); 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); }  } }