I am brand new to arduino and I have been experimenting with coding the things for the past few weekends. I have used basic and visual basic in the past but it has been a while. I have almost no experience in C++. This is the project where I think I might have learned how a subroutine works and how to make libraries. If I take the entire bottom part of the code and save it as an .h file I think that is a library right? This is what I came up with and its a work in progress. I hope this might be able to help others that are starting off too!!
I installed RGB leds under the desk components in my office/ electronics lab with the intention of connecting them to a home automation system. The home automation system (still trying to make this part) will communicate different messages based on colors and blink patterns of leds. When its not telling me a message I want it to do blinky stuff to music. At some point I need to get a pwm chip to make more outputs. I think I figured out what to do with that but any ideas would be helpful to get that last channel by itself. Let me know what you think and like I said I hope this helps other people!
link to video
// This code was written by jx02123
// I have 5 lights connected to this setup and I tried to use the digital outputs because I didnt have enough PWM. It didnt work so most of the commands are written to use 4 lights.
// Anywhere the redp, greenp, and bluep are located are just turned off to leave if I come back to mess around with that.
// address whatever your pinouts for your rgb leds are here. I have my led strips connected and controled by tip 122 transistors.
int red1 = 10;
int green1 = 9;
int blue1 = 8;
int red2 = 7;
int green2 = 6;
int blue2 = 5;
int red3 = 13;
int green3 = 12;
int blue3 = 11;
int red4 = 4;
int green4 = 3;
int blue4 = 2;
int redp = 22;
int greenp = 24;
int bluep = 26;
// general delays that I have been using inbetween different effects
int ntime = 75;
int dtime = 300;
void setup(){
digitalWrite(redp, LOW);
digitalWrite(bluep, LOW);
digitalWrite(greenp, LOW);
analogWrite(red1, 0);
analogWrite(blue1, 0);
analogWrite(green1, 0);
analogWrite(red2, 0);
analogWrite(blue2, 0);
analogWrite(green2, 0);
analogWrite(red3, 0);
analogWrite(blue3, 0);
analogWrite(green3, 0);
analogWrite(red4, 0);
analogWrite(blue4, 0);
analogWrite(green4, 0);
}
void loop()
{
rotateR(255,255,0,75);
rotateR(255,0,0,75);
rotateR(0,0,255, 75);
rotateR(0,255,0,75);
rotateR(255,255,255,50);
}
void all(int r, int g, int b) //ALL Lights (r, g, b)
{
digitalWrite(redp, LOW);
digitalWrite(bluep, LOW);
digitalWrite(greenp, LOW);
analogWrite(red1, r);
analogWrite(blue1, b);
analogWrite(green1, g);
analogWrite(red2, r);
analogWrite(blue2, b);
analogWrite(green2, g);
analogWrite(red3, r);
analogWrite(blue3, b);
analogWrite(green3, g);
analogWrite(red4, r);
analogWrite(blue4, b);
analogWrite(green4, g);
}
void light1 (int r, int g, int b)
{
analogWrite(red1, r);
analogWrite(blue1, b);
analogWrite(green1, g);
}
void light2 (int r, int g, int b)
{
analogWrite(red2, r);
analogWrite(blue2, b);
analogWrite(green2, g);
}
void light3 (int r, int g, int b)
{
analogWrite(red3, r);
analogWrite(blue3, b);
analogWrite(green3, g);
}
void light4 (int r, int g, int b)
{
analogWrite(red4, r);
analogWrite(blue4, b);
analogWrite(green4, g);
}
void blinkall (int r, int g, int b, int R, int G, int B, int d)
{
all(r, g, b);
delay(d);
all(R, G, B);
delay(d);
all(r, g, b);
delay(d);
all(R, G, B);
delay(d);
all(r, g, b);
delay(d);
all(R, G, B);
delay(d);
all(r, g, b);
delay(d);
all(R, G, B);
delay(d);
all(r, g, b);
delay(d);
all(R, G, B);
delay(d);
all(r, g, b);
delay(d);
all(R, G, B);
delay(250);
}
void blinkright(int r, int g, int b, int R, int G, int B, int d)// lowercase and uppercase are the two colors to blink back and forth. If you wanted you can blink green and red with 255,0,0,0,255,0,100 for example with a delay time of 100. It pauses at the end for twice the delay
{
right(r, g, b);
delay(d);
right(R, G, B);
delay(d);
right(r, g, b);
delay(d);
right(R, G, B);
delay(d);
right(r, g, b);
delay(d);
right(R, G, B);
delay(d);
right(r, g, b);
delay(d);
right(R, G, B);
delay(d);
right(r, g, b);
delay(d);
right(R, G, B);
delay(d);
right(r, g, b);
delay(d);
right(R, G, B);
delay(d*2);
}
void blinkleft(int r, int g, int b, int R, int G, int B, int d)
{
left(r, g, b);
delay(d);
left(R, G, B);
delay(d);
left(r, g, b);
delay(d);
left(R, G, B);
delay(d);
left(r, g, b);
delay(d);
left(R, G, B);
delay(d);
left(r, g, b);
delay(d);
left(R, G, B);
delay(d);
left(r, g, b);
delay(d);
left(R, G, B);
delay(d);
left(r, g, b);
delay(d);
left(R, G, B);
delay(250);
}
void right (int r, int g, int b)// this is the right half of the light display turning the left off
{
light3(r, g, b);
light4(r, g, b);
light1(0,0,0);
light2(0,0,0);
}
void left (int r, int g, int b) // this is the left half of the light display turning the right off
{
light1 (r, g, b);
light2 (r, g, b);
light3 (0,0,0);
light4 (0,0,0);
}
void rotateR(int r, int g, int b, int d) // rotates to the right one light at a time with short pause at end = to double delay set
{
digitalWrite(redp, LOW);
digitalWrite(bluep, LOW);
digitalWrite(greenp, LOW);
all(0,0,0);
light1(r,g,b);
delay(d);
all(0,0,0);
light2(r,g,b);
delay(d);
all(0,0,0);
light3(r,g,b);
delay(d);
all(0,0,0);
light4(r,g,b);
delay(2*d);
all(0,0,0);
}
void rotateL(int r, int g, int b, int d) // rotates to the left one light at a time with short pause at end = to double delay set
{
digitalWrite(redp, LOW);
digitalWrite(bluep, LOW);
digitalWrite(greenp, LOW);
all(0,0,0);
light4(r,g,b);
delay(d);
all(0,0,0);
light3(r,g,b);
delay(d);
all(0,0,0);
light2(r,g,b);
delay(d);
all(0,0,0);
light1(r,g,b);
delay(2*d);
all(0,0,0);
}