int light = 1; //Defines light mode variable and resets value
void setup() {
// put your setup code here, to run once:
pinMode(5, OUTPUT); //sets output to control red
pinMode(3, OUTPUT); //sets output to control green
pinMode(4, OUTPUT); //sets output to control blue
pinMode(6, INPUT); //sets input pin for UI
Serial.begin(9600); // opens the serial port at 9600 bps:
Serial.print("Debug channel started"); //notify's tec that connection was established
Serial.print('\n'); //creates new line
Serial.print("Light mode "); //Adds label
Serial.print(light); //prints the mode value
}
void loop() {
// put your main code here, to run repeatedly:
if (light == 1) {
White(); //sets light color to white
}
if (light == 2) {
digitalWrite(5, LOW);
}
if (light == 3) {
digitalWrite(3, LOW);
}
if (light == 4) {
digitalWrite(4, LOW);
}
if (light == 5) {
digitalWrite(5, LOW); //sets light to red
delay(550);
reset(); //resets light color
digitalWrite(3, LOW); //sets light to green
delay(550);
reset(); //resets light color
digitalWrite(4, LOW); //sets light to blue
delay(550);
}
if (light == 6) {
delay(550);
digitalWrite(5, LOW); //sets light to red
delay(550);
reset(); //resets light color
delay(550);
digitalWrite(3, LOW); //sets light to green
delay(550);
reset(); //resets light color
delay(550);
digitalWrite(4, LOW); //sets light to blue
delay(550);
}
if (light == 7) {
digitalWrite(5, LOW);
delay(550);
reset();
delay(550);
}
//mode 8 is free and can be defined
//mode 9 is free and can be defined
CheckButton(); //checks if button is pressed
reset(); //resets light color
}
void White() {
//Sets light color to white
digitalWrite(5, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}
void reset() {
//Resets pins to turn lights off
digitalWrite(5, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
}
void CheckButton() {
//checks if button is pressed
if (digitalRead(6) == HIGH) { //checks if button is pressed
while(digitalRead(6) == HIGH) { //repeats code until button is released
delay(20); //Delays
}
if (light == 9) { //if light = 9 then ligth gets set to 1 else light is changed by 1
light = 1;
} else {
light = light + 1;
}
Serial.print('\n'); //creates new line
Serial.print("Light mode "); //Adds label
Serial.print(light); //prints the mode value
}
}