Good day. Im new here, but a long time reader and a long time user of arduino, but i still consider myself nooob. I try now to make some PC lights, and a part of it involves using the adalights with the ambibox software. But, that is optional. and only as a function, that is used when i have serial active. I
ve made the code modular already, so no point into posting all the code , as the rest of the code are fastled effects etc.
My problem is the following: when i select the Serial function (will post code) which is the Adalight code, i got from someone else, it works perfectly. but, when i select something else, this code get stuck in a waiting loop, thus then next selected function does not work.
void serial () {
// wait for first byte of Magic Word
for(i = 0; i < sizeof prefix; ++i) {
Serial.print ("must escape this");
waitLoop: while (!Serial.available()) ;;
// Check next byte in Magic Word
if(prefix[i] == Serial.read()) continue;
// otherwise, start over
i = 0;
goto waitLoop;
}
// Hi, Lo, Checksum
while (!Serial.available()) ;;
hi=Serial.read();
while (!Serial.available()) ;;
lo=Serial.read();
while (!Serial.available()) ;;
chk=Serial.read();
s = 1 ;
// if checksum does not match go back to wait
if (chk != (hi ^ lo ^ 0x55))
{
i=0;
goto waitLoop;
}
memset(leds, 0, NUM_LEDS * sizeof(struct CRGB));
// read the transmission data and set LED values
for (uint8_t i = 0; i < NUM_LEDS; i++) { // replace for with if here
byte r, g, b;
while(!Serial.available());
r = Serial.read();
while(!Serial.available());
g = Serial.read();
while(!Serial.available());
b = Serial.read();
//Change Variables to match output if strand is mismatched or try changing order of rgb in controller definition at top
leds[i].r = r;
leds[i].g = g;
leds[i].b = b;
}
// shows new values
FastLED.show();
}
my question is:
is there a chance i could modify the code to make this not use a loop?
i want to say that i dont care about how fast it will work, because it will just do colour changing.
kind regards, Loren