Hideho folks, new here and need to pick some brains.
I’m running a matrix through an arduino nano and all is fine but what I’m trying to do is when there’s no serial data from Jinx ie it’s not running things; to switch to some simple fastled palettes cycling.
Now I’ve kind of got it working in that when there’s no serial input it’ll show a palette but I’m stuck trying to get it to initialise for Jinx. It detects the serial input and turns off the fastled palette but it won’t start the Jinx input.
I’m probably doing something incredibly stupid and the answer is most likely staring at me in the face so if someone can have a look and point me in the right direction it;d be really appreciated.
#include "FastLED.h"
#define NUM_LEDS 256
#define DATA_PIN 9
#define BRIGHTNESS 100
CRGB leds[NUM_LEDS];
#define UPDATES_PER_SECOND 100
CRGBPalette16 currentPalette;
TBlendType currentBlending;
void setup() {
currentPalette = ForestColors_p;
currentBlending = LINEARBLEND;
Serial.begin(500000);
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
}
int serialJinx () {
while (!Serial.available()) {}
return Serial.read();
}
void loop()
{
if (Serial.read() > 0) {
jinx();
}
else if (Serial.read() == -1) {
internal();
}
}
void jinx(){
while (serialJinx () != 1) {}
for (int i = 0; i < NUM_LEDS; i++)
{
leds[i].r = serialJinx ();
leds[i].g = serialJinx ();
leds[i].b = serialJinx ();
}
}
void internal()
{
uint8_t brightness = 40;
for ( int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette( currentPalette, brightness, currentBlending);
}
FastLED.show();
FastLED.delay(1000 / UPDATES_PER_SECOND);
}