Hi All
I’ve just dipped my toes into the wonderful world of electronics. Primarily for use on Dioramas and Table Top Gaming terrain.
I’m using an Uno, and trying to have 3 things happen:
Function 1: 5 x RGB Led’s, all on the same line, fading between Green and Yellow.
Function 2: 2 x Blue LED’s, each powered on by 2 x magnetic reed switches.
Function 3: 1 x RGB LED that’s colour is dependant on the state of the above switches (Green if both switches are powered on, orange if only one switch is powered on and red if both switches are off).
For my test circuit I’ve only used a single RGB LED for Function 1, these will all be connected along a single line. Diagram attached.
Now the code, and this is the part where I’m super noob!
int ooze_red_light_pin= 11;
int ooze_blue_light_pin = 10;
int ooze_green_light_pin = 9;
int red_light_pin= 6;
int blue_light_pin = 5;
int green_light_pin = 3;
int switch_1_pin = 1;
int switch_2_pin = 2;
void setup() {
pinMode(ooze_red_light_pin, OUTPUT);
pinMode(ooze_green_light_pin, OUTPUT);
pinMode(ooze_blue_light_pin, OUTPUT);
pinMode(red_light_pin, OUTPUT);
pinMode(green_light_pin, OUTPUT);
pinMode(blue_light_pin, OUTPUT);
pinMode(switch_1_pin, OUTPUT);
pinMode(switch_2_pin, OUTPUT);
}
void loop() {
digitalWrite(switch_1_pin, HIGH);
digitalWrite(switch_2_pin, HIGH);
// If both pins are high, set green
if(switch_1_pin == HIGH && switch_2_pin == HIGH)
{
RGB_color_2(0, 255, 0); //Green
}
// else if one pin is high, set orange maybe
else(switch_1_pin == HIGH || switch_2_pin == HIGH
{
RGB_color_2(127,255,0); // Some colour??
}
// if neither of the top, make it red
else
{
RGB_color_2(255, 0, 0); //Red
}
delay(100);
}
RGB_color_1(0, 255, 0); // Green
delay(150);
RGB_color_1(65, 255, 0); // Greener Yellow
delay(150);
RGB_color_1(127, 255, 0); // Green/Yellow
delay(150);
RGB_color_1(190, 255, 0); // Yellower Green
delay(150);
RGB_color_1(255, 255, 0); // Yellow
delay(150);
RGB_color_1(190, 255, 0); // Yellower Green
delay(150);
RGB_color_1(127, 255, 0); // Green/Yellow
delay(150);
RGB_color_1(65, 255, 0); // Greener Yellow
delay(100);
}
void RGB_color_1(int red_light_value, int green_light_value, int blue_light_value)
{
analogWrite(ooze_red_light_pin, red_light_value);
analogWrite(ooze_green_light_pin, green_light_value);
analogWrite(ooze_blue_light_pin, blue_light_value);
}
void RGB_color_2(int red_light_value, int green_light_value, int blue_light_value)
{
analogWrite(red_light_pin, red_light_value);
analogWrite(green_light_pin, green_light_value);
analogWrite(blue_light_pin, blue_light_value);
}
First off: Is what I’m trying to do with the switches even possible? Or do I need to alter the circuit?
Any help would be greatly appreciated