Hi All,
I'm new to Arduino and new to the forum.
My street is pretty into their Xmas lights and last year i decided i was going to make alittle more of a effort this coming year. I have a decent size(not xmas tree) tree in the front yard and my plan is to apply this project to this tree.
Plan:
Buy several different types of xmas lights, different colours/ effects.
Load them all into the tree and have and have a pedestal of some sort on the grass with a big red button that activates different relays one by one when the button is pressed effectively making the Xmas lights interactive.
My coding is not the best, I've basically been following through some tutorials and having a struggle to figure out how to do what I want.
I have managed to find some else's previous project that does something similar except each relay has its own button. I'm wondering if someone could point me in the right direction in editing the below code to achieve my purpose (one button that's activates the relays sequentially as appose to 4 buttons)
Acknowledgements to rawrrr_x3_xoxo as I stole this code from his 2018 post.
“Imitation is the sincerest form of flattery that mediocrity can pay to greatness.”
― Oscar Wilde
// Guitar amp relay module driven my microcontroller input
// 2018 - Eric Carlson - ECS Audio
int relay1 = 12; //Amp CH1 relay
int relay2 = 11; //Amp CH2 relay
int relay3 = 10; //Amp CH3 relay
int relay4 = 9; //Amp CH4 relay
int button1 = 2; //CH1 Button
int button2 = 3; //CH2 Button
int button3 = 4; //CH3 Button
int button4 = 5; //CH4 Button
void setup()
{
// Initialize digital output pins for relays:
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
// Initialize digital inputs with internal pullup resistors:
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
pinMode(button3, INPUT_PULLUP);
pinMode(button4, INPUT_PULLUP);
//Set the initial startup to CH1:
digitalWrite(relay1, LOW);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, HIGH);
}
void loop()
{
//CH1 EN
bool button1State ;
button1State = digitalRead(button1);
if(button1State == LOW)
{
digitalWrite(relay1, LOW);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, HIGH);
}
//CH2 EN
bool button2State ;
button2State = digitalRead(button2);
if(button2State == LOW)
{
digitalWrite(relay2, LOW);
digitalWrite(relay1, HIGH);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, HIGH);
}
//CH3 EN
bool button3State ;
button3State = digitalRead(button3);
if(button3State == LOW)
{
digitalWrite(relay3, LOW);
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
digitalWrite(relay4, HIGH);
}
//CH4 EN
bool button4State ;
button4State = digitalRead(button4);
if(button4State == LOW)
{
digitalWrite(relay4, LOW);
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);
}
}
Thanks to everyone that made it to the end of my post