//Whipplashes
//Code orginally taken from inventr.io and modified to fit the needs of this project
//4-21-22
int red = 11; //output
int green = 10;
int blue = 9;
int Switch1 = 2; //Input
int Switch2 = 3;
int Switch3 = 4;
void setup() {
// Setup pins
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
pinMode(Switch1, INPUT);
pinMode(Switch2, INPUT);
pinMode(Switch3, INPUT);
}
void RGB_color(int red_value, int green_value, int blue_value)
{
// RBG function to pass on color values
analogWrite(red, red_value);
analogWrite(green, green_value);
analogWrite(blue, blue_value);
}
void loop() { //Various if and if else statments designed to trigger once only when the corresponding values on the breadboard are selected.
if (digitalRead(Switch1) == HIGH && digitalRead(Switch2) != HIGH && digitalRead(Switch3) != HIGH)
{
RGB_color(125, 0, 0); // Red
delay(800);
RGB_color(0, 125, 0); // Green
delay(800);
}
else if (digitalRead(Switch2) == HIGH && digitalRead(Switch1) != HIGH && digitalRead(Switch3) != HIGH)
{
RGB_color(0, 0, 125); // Blue
delay(800);
RGB_color(64, 32, 0); // yellow
delay(800);
}
else if (digitalRead(Switch3) == HIGH && digitalRead(Switch2) != HIGH && digitalRead(Switch1) != HIGH)
{
RGB_color(125, 0, 125); // purple
delay(800);
RGB_color(125, 125, 125); // white
delay(800);
}
else if (digitalRead(Switch1) == HIGH && digitalRead(Switch2) == HIGH && digitalRead(Switch3) != HIGH)
{
RGB_color(125, 0, 0); // Red
delay(800);
RGB_color(0, 125, 0); // Green
delay(800);
RGB_color(0, 0, 125); // Blue
delay(800);
RGB_color(64, 32, 0); // yellow
delay(800);
}
else if (digitalRead(Switch1) == HIGH && digitalRead(Switch3) == HIGH && digitalRead(Switch2) != HIGH)
{
RGB_color(125, 0, 0); // Red
delay(800);
RGB_color(0, 125, 0); // Green
delay(800);
RGB_color(125, 0, 125); // purple
delay(800);
RGB_color(125, 125, 125); // white
delay(800);
}
else if (digitalRead(Switch2) == HIGH && digitalRead(Switch3) == HIGH && digitalRead(Switch1) != HIGH)
{
RGB_color(0, 0, 125); // Blue
delay(800);
RGB_color(64, 32, 0); // yellow
delay(800);
RGB_color(125, 0, 125); // purple
delay(800);
RGB_color(125, 125, 125); // white
delay(800);
}
else if (digitalRead(Switch2) == HIGH && digitalRead(Switch3) == HIGH && digitalRead(Switch1) == HIGH)
{
RGB_color(125, 0, 0); // Red
delay(800);
RGB_color(0, 125, 0); // Green
delay(800);
RGB_color(0, 0, 125); // Blue
delay(800);
RGB_color(64, 32, 0); // yellow
delay(800);
RGB_color(125, 0, 125); // purple
delay(800);
RGB_color(125, 125, 125); // white
delay(800);
}
else if (digitalRead(Switch2) != HIGH && digitalRead(Switch3) != HIGH && digitalRead(Switch1) != HIGH)
{
RGB_color(0,0,0);
delay(500);
}
}
Comments