#include #define LED_PIN 9 #define COLOR_ORDER GRB #define CHIPSET WS2812 #define NUM_LEDS 64 #define BRIGHTNESS 64 #define NUM_ROWS 8 #define NUM_COLS 8 CRGB leds[NUM_LEDS]; int color_idx = 0; void setup() { int index = 0; Serial.begin(115200); FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalSMD5050); FastLED.setBrightness( BRIGHTNESS ); // Zet alles uit. fill_solid(leds, NUM_LEDS, CRGB(0,0,25)); FastLED.show(); delay(200); fill_solid(leds, NUM_LEDS, CRGB::Black); FastLED.show(); delay(400); } void LED_uit(int x, int y) { int index = x; index += y*8; leds[index] = CRGB::Black ; FastLED.show(); } void LED_aan(int x, int y, CRGB& color) { int index = x; index += y*8; leds[index] = color ; FastLED.show(); } int color_idx_inc(int color_idx) { color_idx = color_idx + 4; if (color_idx >= 255) return 0; else return color_idx; } int direction_find(int x, int y) { int direction = 90; if ((x == 0) && (y > 0)) direction = 0; if ((x == NUM_COLS -1) && (y < NUM_COLS-1)) direction = 180; if ((x < NUM_COLS-1)&& (y == 0)) direction = 90; if ((x > 0) && (y == NUM_ROWS -1)) direction = 270 ; return direction; } int next_x(int x, int direction){ if (direction == 90 ) return ++x; else if (direction == 270) return --x; else return x; } int next_y(int y, int direction){ if (direction == 180 ) return ++y; else if (direction == 0) return --y; else return y; } void loop() { char error_string[256]; static int x = 0; static int y = 0; struct CRGB color = CHSV(0,255,255) ; static int color_idx =0 ; int direction = 90; direction = direction_find(x,y); x = next_x(x, direction ); y = next_y(y, direction ); sprintf(error_string, "x: %i, y: %i direction: %03i, color_idx: %03i", x, y, direction, color_idx); Serial.println(error_string); color_idx = color_idx_inc(color_idx); color = CHSV(color_idx,255,255); LED_aan(x, y, color); FastLED.show(); delay(100); LED_uit(x, y); }