Hello! I'm new to the forum (been looking for tutorials since I don't remember),
I'm working with rgb leds (this type Screenshot by Lightshot) and I'm trying to make them blink using millis. The general idea is when it blinks, blink with another color, it could be a random color or with a secuence (red, green,blue) But I don't know how to adress this problem.
It worked with delay, but when I switch mode with a button, it needs to wait to the loop to end.
The other problem I have is that I need to control more than 4 rgb leds at once, with differents secuences, but with the pwn I can only use 2 leds, what can I do?
This is the code working with delay...
int buttonPin1=2;
int redPin1=11;
int greenPin1=10;
int bluPin1=9;
int buttonState=0;
void setup()
{
pinMode(buttonPin1, INPUT);
pinMode(redPin1, OUTPUT);
pinMode(greenPin1, OUTPUT);
pinMode(bluPin1, OUTPUT);
}
void loop()
{
buttonState=digitalRead(buttonPin1);
if (buttonState == LOW)
{
setColor1(255, 0, 0); // red
delay(1000);
setColor1(0, 255, 0); // green
delay(1000);
setColor1(0, 0, 255); // blue
delay(1000);
setColor1(255, 255, 0); // yellow
delay(1000);
setColor1(80, 0, 80); // purple
delay(1000);
setColor1(0, 255, 255); // aqua
delay(1000);
setColor1(75, 0, 130); // indigo
delay(5000);
setColor1(255, 255, 255); //blancoo
delay(2500);
}
if (buttonState == HIGH)
{
setColor1(255, 0, 0); // red
delay(100);
setColor1(0, 255, 0); // green
delay(100);
setColor1(0, 0, 255); // blue
delay(100);
}
}
void setColor1(int red1,int green1,int blu1)
{
analogWrite(redPin1,red1);
analogWrite(greenPin1,green1);
analogWrite(bluPin1,blu1);
}