From 3d34021a100cd2d04c08cbc9da568046cc82d7f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B8vbr=C3=B8tte=20Olsen?= Date: Tue, 3 Jan 2017 00:00:38 -0800 Subject: [PATCH] Added borg --- School/borg/borg.h | 92 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 School/borg/borg.h diff --git a/School/borg/borg.h b/School/borg/borg.h new file mode 100644 index 0000000..0caabb4 --- /dev/null +++ b/School/borg/borg.h @@ -0,0 +1,92 @@ +#ifndef borg_h +#define borg_h + +#include "Arduino.h" +#include + +struct LEDSelect { + byte side; + byte column; + byte row; +}; + +// Decodes side, column, row into n LED +int decodeLED(LEDSelect selection); +bool setColor(LEDSelect selection, CRGB* leds); +bool updateColor(LEDSelect selection, CRGB* leds); + +int decodeLED(LEDSelect selection) { + return 9 * selection.side + 3 * selection.row + selection.column; +} + +bool setColor(LEDSelect selection, CRGB color, CRGB* leds) { + if (selection.side == 255) { + return false; + } + if (selection.column == 255 && selection.row == 255) { + for (byte n = 0; n < 9; n++) { + leds[selection.side * 9 + n] = color; + } + return true; + } + else if (selection.column == 255 && selection.row != 255) { + for (byte n = 0; n < 3; n++) { + leds[decodeLED({ selection.side, n, selection.row })] = color; + } + return true; + } + else if (selection.column != 255 && selection.row == 255) { + for (byte n = 0; n < 3; n++) { + leds[decodeLED({ selection.side, selection.column, n })] = color; + } + return true; + } + else if (selection.column != 255 && selection.row != 255) { + leds[decodeLED(selection)] = color; + return true; + } + else { + return false; + } +} + + +bool updateColor(LEDSelect selection, CRGB color, CRGB* leds) { + if (selection.side == 255) { + return false; + } + if (selection.column == 255 && selection.row == 255) { + for (int n = 0; n < 9; n++) { + CRGB* led = &leds[selection.side * 9 + n]; + if (*led != (CRGB)0x000000)*led = color; + } + return true; + } + else if (selection.column == 255 && selection.row != 255) { + for (int n = 0; n < 3; n++) { + CRGB* led = &leds[decodeLED({ selection.side, n, selection.row })]; + if (*led != (CRGB)0x000000)*led = color; + } + return true; + } + else if (selection.column != 255 && selection.row == 255) { + for (int n = 0; n < 3; n++) { + CRGB* led = &leds[decodeLED({ selection.side, selection.column, n })]; + if (*led != (CRGB)0x000000)*led = color; + } + return true; + } + else if (selection.column != 255 && selection.row != 255) { + CRGB* led = &leds[decodeLED(selection)]; + if (*led != (CRGB)0x000000) { + *led = color; + } + return true; + } + else { + return false; + } +} + + +#endif \ No newline at end of file