so, I made a post here a while ago about an Arduino code. that code controls my RGB led strips. now I want to add a rainbow functionality. I used an RGB speaker software for a while, this is what they used:
case 'f': speed = Serial.parseInt();
intensity = Serial.parseInt();
fadeRGB(speed, intensity);
flushSerial();
return true;
break;
In my code, 1 is off, 2 is on, and 3 + RGB value sets a color. so 4 +speed would make a rainbow!
could anyone help me with this? thanks!
code:
I am making a computer controlled RGB controller, I have my code made. but I want to add rainbow functionality on the serial string 4 + speed. please help me!
code:
int redpin = 3; //intialize all the pins
int greenpin = 5;
int bluepin = 6;
int r = 255; //initialize the rgb values
int g = 255;
int b = 255;
int serial; //initialize the variable to store the serial input
void setup() {
pinMode(redpin, OUTPUT); //set the pins as output
pinMode(greenpin, OUTPUT);
pinMode(bluepin, OUTPUT);
analogWrite(redpin, 0); //turn the pins off
analogWrite(greenpin, 0);
analogWrite(bluepin, 0);
Serial.begin(9600); //begin the serial monitor at 9600 baud
Serial.print("Hello"); //say Hello, be polite!
}
void loop() {
int serial = Serial.read();
if (serial == '1') //if it's 1 the pins turn off
{
analogWrite(redpin, 0); //turn the pins off
analogWrite(greenpin, 0);
analogWrite(bluepin, 0);
Serial.print(" The led's are now off ");
}
else if (serial == '2')//if it's 2 the pins turn on
{
analogWrite(redpin, r); //turn the pins on
analogWrite(greenpin, g);
analogWrite(bluepin, b);
Serial.print(" The led's are now on ");
}
else if (serial == '3')//if it's 3 change the colours
{
r = Serial.parseInt();//look for the next valid integer in the incoming serial stream
g = Serial.parseInt();//do it again
b = Serial.parseInt();//and again
analogWrite(redpin, r); //turn the pins on
analogWrite(greenpin, g);
analogWrite(bluepin, b);
//for debugging:
Serial.print(" ");
Serial.print(r);
Serial.print(" ");
Serial.print(g);
Serial.print(" ");
Serial.print(b);
Serial.print(" ");
}
else if (serial == '4')//if it's 3 change the colours
{
Serial.print(" ");
Serial.print(r);
Serial.print(" ");
Serial.print(g);
Serial.print(" ");
Serial.print(b);
Serial.print(" ");
}
}