diff --git a/src/components/neo-ringlight/.theia/launch.json b/src/components/neo-ringlight/.theia/launch.json deleted file mode 100644 index 87f7a80..0000000 --- a/src/components/neo-ringlight/.theia/launch.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - "version": "0.2.0", - "configurations": [ - - { - "cwd": "${workspaceRoot}", - "executable": "./bin/executable.elf", - "name": "Debug Microcontroller", - "request": "launch", - "type": "cortex-debug", - "servertype": "pyocd" - } - ] -} diff --git a/src/components/neo-ringlight/neo-ringlight.ino b/src/components/neo-ringlight/neo-ringlight.ino index 5264dae..eca4221 100644 --- a/src/components/neo-ringlight/neo-ringlight.ino +++ b/src/components/neo-ringlight/neo-ringlight.ino @@ -21,12 +21,26 @@ typedef union { typedef uint8_t Color[3]; // GLOBAL VARIABLES -size_t read = 0; +uint32_t read = 0; uint8_t message[SERIAL_MESSAGE_LEN] = { 0 }; Address address = { 0 }; Color color = { 0 }; Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); + +uint8_t set_color(uint32_t address, uint8_t r, uint8_t g, uint8_t b) { + if (address == UINT_MAX || address > NUMPIXELS || address < 0) { + pixels.clear(); + for (int i = 0; i < NUMPIXELS; i++) { + pixels.setPixelColor(i, pixels.Color(r, g, b)); + } + pixels.show(); + } else { + pixels.setPixelColor(address, pixels.Color(r, g, b)); + pixels.show(); + } +} + // SETUP PROCEDURE void setup() { #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000) @@ -34,6 +48,16 @@ void setup() { #endif Serial.begin(9600); pixels.begin(); + // show test colors + set_color(-1, 255, 0, 0); + delay(1000); + set_color(-1, 0, 255, 0); + delay(1000); + set_color(-1, 0, 0, 255); + delay(1000); + set_color(-1, 0, 0, 0); + delay(1000); + set_color(-1, 255, 255, 255); } uint8_t parse_message(uint8_t *message, Address *address, Color color) { @@ -55,23 +79,13 @@ uint8_t parse_message(uint8_t *message, Address *address, Color color) { void loop() { read = Serial.readBytes(message, SERIAL_MESSAGE_LEN); if (read > 0 && read != SERIAL_MESSAGE_LEN) { - Serial.write("bad message length: %d instead of %d\n", read, SERIAL_MESSAGE_LEN); + Serial.write("bad message length\n"); return; } if (parse_message(message, &address, color)) { Serial.write(", failed to parse message\n"); return; } - if (address.value == UINT_MAX || address.value > NUMPIXELS) { - pixels.clear(); - for (int i = 0; i < NUMPIXELS; i++) { - pixels.setPixelColor(i, pixels.Color(color[0], color[1], color[2])); - } - pixels.show(); - Serial.write("ok\n"); - } else { - pixels.setPixelColor(i, pixels.Color(color[0], color[1], color[2])); - pixels.show(); - Serial.write("ok\n"); - } + set_color(address.value, color[0], color[1], color[2]); + Serial.write("ok\n"); }