Use 4 space tab like a normal person

This commit is contained in:
Oliver Atkinson 2023-09-05 08:49:30 -06:00
parent a6c46788df
commit a2c5fee6ac

View File

@ -9,10 +9,10 @@ ws2812b<D,6> strip;
grb pixels[NUM_LEDS] = {}; grb pixels[NUM_LEDS] = {};
void setup() { void setup() {
Serial.begin(BAUD); // baud is defined at build time Serial.begin(BAUD); // baud is defined at build time
Serial.println("\nResetting!"); Serial.println("\nResetting!");
strip.clear(NUM_LEDS); strip.clear(NUM_LEDS);
} }
// Don't spend too long in this function, we need to read out // Don't spend too long in this function, we need to read out
@ -20,44 +20,41 @@ void setup() {
void on_serial() void on_serial()
{ {
// How many times have we read? // How many times have we read?
static int read = 0; static int read = 0;
// should be non blocking // should be non blocking
int read_byte = Serial.read(); int read_byte = Serial.read();
int index = (int) read / 3; int index = (int) read / 3;
// the first, second, or third byte // the first, second, or third byte
switch (read % 3) switch (read % 3)
{ {
/* /*
Idk why it's weird like this RBG, but it's easier to change it here. Idk why it's weird like this RBG, but it's easier to change it here.
*/ */
case 0: // first case 0: // first
pixels[index].r = read_byte; pixels[index].r = read_byte;
break; break;
case 1: // second case 1: // second
pixels[index].g = read_byte; pixels[index].g = read_byte;
break; break;
default: // third default: // third
pixels[index].b = read_byte; pixels[index].b = read_byte;
break; break;
} }
// increment or loop
// increment or loop if (read < BUF_SIZE-1) {
if (read < BUF_SIZE-1) { read++;
read++; } else {
} else { // Whole frame as been read, send to the leds
// Whole frame as been read, send to the leds strip.sendPixels(NUM_LEDS, pixels);
strip.sendPixels(NUM_LEDS, pixels); read=0;
read=0; }
}
} }
void loop() { void loop() {
if (Serial.available() > 0) {
if (Serial.available() > 0) { on_serial();
on_serial(); }
}
} }