|
| 1 | +//Libraries |
| 2 | +//https://github.com/FastLED/FastLED |
| 3 | +#include <FastLED.h> |
| 4 | + |
| 5 | +//Constants |
| 6 | +#define NUM_STRIPS 1 |
| 7 | +#define NUM_LEDS 100 |
| 8 | +#define BRIGHTNESS 10 |
| 9 | +#define LED_TYPE WS2812B |
| 10 | +#define COLOR_ORDER BRG//RGB |
| 11 | +#define FASTLED_ALLOW_INTERRUPTS 0 |
| 12 | +#define FASTLED_INTERRUPT_RETRY_COUNT 1 |
| 13 | +#define FRAMES_PER_SECOND 60 |
| 14 | +#define COOLING 55 |
| 15 | +#define SPARKING 120 |
| 16 | + |
| 17 | +//Parameters |
| 18 | +const int stripPin = 3; |
| 19 | + |
| 20 | +//Objects |
| 21 | +CRGB leds[NUM_LEDS]; |
| 22 | + |
| 23 | +int xy2i(int x, int y) { |
| 24 | + int i; |
| 25 | + if ( y % 2 == 0) { |
| 26 | + return i = y * 10 + x; |
| 27 | + } else { |
| 28 | + return i = (10 * (y + 1)) - 1 - x; |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +int toDrawA[10][10][3]= |
| 33 | +{ |
| 34 | +{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, |
| 35 | +{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, |
| 36 | +{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, |
| 37 | +{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, |
| 38 | +{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, |
| 39 | +{{0, 0, 0}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, |
| 40 | +{{0, 0, 0}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {255, 0, 0}, {255, 0, 0}, {0, 0, 0}, {0, 0, 0}}, |
| 41 | +{{0, 0, 0}, {0, 0, 0}, {255, 0, 0}, {255, 0, 0}, {255, 0, 0}, {255, 0, 0}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}, {0, 0, 0}}, |
| 42 | +{{0, 0, 0}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}, {0, 0, 0}}, |
| 43 | +{{0, 0, 0}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, |
| 44 | +}; |
| 45 | + |
| 46 | + |
| 47 | +String command; |
| 48 | + |
| 49 | +String colorArray[5]; |
| 50 | + |
| 51 | + |
| 52 | +int l; |
| 53 | +int cR, cG, cB; |
| 54 | + |
| 55 | +const int NUM_ROWS = 10; |
| 56 | +const int NUM_COLS = 10; |
| 57 | + |
| 58 | + |
| 59 | +void displayImage(int toDraw[10][10][3]) { |
| 60 | + |
| 61 | + FastLED.clear(); |
| 62 | + |
| 63 | + for ( int y = 0; y < 10; y++) { |
| 64 | + for (int x = 0; x < 10; x++) { |
| 65 | + l = xy2i(x, y); |
| 66 | + cR = toDraw[y][x][0]; |
| 67 | + cG = toDraw[y][x][1]; |
| 68 | + cB = toDraw[y][x][2]; |
| 69 | + leds[l].setRGB(cR, cG, cB); |
| 70 | + } |
| 71 | + } |
| 72 | + FastLED.show(); |
| 73 | +} |
| 74 | + |
| 75 | +void setup() { |
| 76 | + Serial.begin(9600); |
| 77 | + FastLED.addLeds<LED_TYPE, stripPin, COLOR_ORDER>(leds, NUM_LEDS); |
| 78 | + FastLED.setBrightness( BRIGHTNESS ); |
| 79 | + |
| 80 | + FastLED.clear(); |
| 81 | + FastLED.show(); |
| 82 | +} |
| 83 | + |
| 84 | + |
| 85 | +int alpha2color(int old_value) { |
| 86 | + int new_value = int((old_value - 97) * (255.0 / 25.0)); |
| 87 | + return new_value; |
| 88 | +} |
| 89 | + |
| 90 | + |
| 91 | +void loop() { |
| 92 | + |
| 93 | + while (Serial.available() == 0) {} |
| 94 | + |
| 95 | + FastLED.clear(); |
| 96 | + FastLED.show(); |
| 97 | + |
| 98 | + |
| 99 | + command = Serial.readString(); |
| 100 | + command.trim(); |
| 101 | + |
| 102 | + if (command == "clear") { |
| 103 | + Serial.println(F("Clear")); |
| 104 | + for (int i=0; i < 100; i++) { |
| 105 | + leds[i].setRGB(0, 0, 0); |
| 106 | + } |
| 107 | + FastLED.show(); |
| 108 | + } else if (command == "letter") { |
| 109 | + Serial.println(F("Letter")); |
| 110 | + displayImage(toDrawA); |
| 111 | + FastLED.show(); |
| 112 | + } else { |
| 113 | + byte colors[NUM_ROWS][NUM_COLS][3]; |
| 114 | + |
| 115 | + int index = 0; |
| 116 | + for (int row = 0; row < NUM_ROWS; row++) { |
| 117 | + for (int col = 0; col < NUM_COLS; col++) { |
| 118 | + int r = command.charAt(index++); |
| 119 | + int v = command.charAt(index++); |
| 120 | + int b = command.charAt(index++); |
| 121 | + |
| 122 | + r = alpha2color(r); |
| 123 | + v = alpha2color(v); |
| 124 | + b = alpha2color(b); |
| 125 | + |
| 126 | + int l = xy2i(col, row); |
| 127 | + leds[l] = CRGB( r, v, b); |
| 128 | + } |
| 129 | + } |
| 130 | + FastLED.show(); |
| 131 | + } |
| 132 | + |
| 133 | +} |
0 commit comments