Hi, this is what I try to do:
BUTTON1 >> Turns my rgb strip led to white
BUTTON0 >> Activates disco mode (turns red and then green, blue etc.)
I'm trying to achieve this, but disco mode requires loop because it changes the color all the time. However, if there is a loop, it means I cannot change the color back to white (pressing BUTTON1).
As a result of days of researchment, I learnt that I shouldn't make any loop, void loop() must do the trick but I couldn't get what should I do instead of loops.
#include <IRremote.hpp>
#define K1 0X87
#define K0 0X92
#define left 0X9B
#define right 0X99
int full_brightness = 255;
int zero_brightness = 0;
int half_brightness = 128;
int R = 6;
int G = 3;
int B = 5;
int brightness = 255;
int i = 1;
int y = 1;
void setup()
{
Serial.begin(9600);
IrReceiver.begin(2, ENABLE_LED_FEEDBACK); // Start the receiver
pinMode(R, OUTPUT);
pinMode(G, OUTPUT);
pinMode(B, OUTPUT);
}
void loop() {
if (i + y < 10) {
}
if (IrReceiver.decode()) {
IrReceiver.printIRResultShort(&Serial);
if (IrReceiver.decodedIRData.command == K1) {
white();
}
if (IrReceiver.decodedIRData.command == K0) {
discoMode();
}
IrReceiver.resume();
}
}
void discoMode() {
// R colour
analogWrite(R, full_brightness);
analogWrite (G, zero_brightness);
analogWrite(B, zero_brightness);
delay(500);
//G colour
analogWrite(R, zero_brightness);
analogWrite (G, full_brightness);
analogWrite(B, zero_brightness);
delay(500);
//B colour
analogWrite(R, zero_brightness);
analogWrite (G, zero_brightness);
analogWrite(B, full_brightness);
}
///////////////////-/>trash<\-\\\\\\\\\\\\\\\\\\\
void white() {
analogWrite(R, 255);
analogWrite(G, 255);
analogWrite(B, 255);
Serial.println("WHITE");
}
In this example disco mode runs for just one time but I want it to be infinite and when I press another button it should break the loop, do what the code says.
But as I said, people tell there shouldn't be any loop but I cannot make it infinite with if statement or something like that.
I hope you got me. Here is my last hope.