#include #define NUM_LEDS 50 #define DATA_PIN 4 #define INTR_PIN 2 #define VIZUALIZATIONS 2 CRGB pixels[NUM_LEDS]; unsigned char offset = 0; void (*viz[VIZUALIZATIONS])(unsigned char); volatile unsigned char currentViz = 0; void viz1(unsigned char offset) { for (unsigned char i = 0; i < NUM_LEDS; i++) pixels[(i + offset) % NUM_LEDS] = CRGB(128 + floor(127 * sin(2 * 3.1415926 * i / NUM_LEDS)), 0, 0); } void viz2(unsigned char offset) { for (unsigned char i = 0; i < NUM_LEDS; i++) pixels[i] = 0; pixels[offset % NUM_LEDS] = CRGB(0x0F, 0xF, 0xF); pixels[(offset + 1) % NUM_LEDS] = CRGB(0x1F, 0xE, 0xE); pixels[(offset + 2) % NUM_LEDS] = CRGB(0x2F, 0xD, 0xD); pixels[(offset + 3) % NUM_LEDS] = CRGB(0x3F, 0xC, 0xC); pixels[(offset + 4) % NUM_LEDS] = CRGB(0x4F, 0xB, 0xB); pixels[(offset + 5) % NUM_LEDS] = CRGB(0x5F, 0xA, 0xA); pixels[(offset + 6) % NUM_LEDS] = CRGB(0x6F, 0x9, 0x9); pixels[(offset + 7) % NUM_LEDS] = CRGB(0x7F, 0x8, 0x8); pixels[(offset + 8) % NUM_LEDS] = CRGB(0x8F, 0x7, 0x7); pixels[(offset + 9) % NUM_LEDS] = CRGB(0x9F, 0x6, 0x6); pixels[(offset + 10) % NUM_LEDS] = CRGB(0xAF, 0x5, 0x5); pixels[(offset + 11) % NUM_LEDS] = CRGB(0xBF, 0x4, 0x4); pixels[(offset + 12) % NUM_LEDS] = CRGB(0xCF, 0x3, 0x3); pixels[(offset + 13) % NUM_LEDS] = CRGB(0xDF, 0x2, 0x2); pixels[(offset + 14) % NUM_LEDS] = CRGB(0xEF, 0x1, 0x1); pixels[(offset + 15) % NUM_LEDS] = CRGB(0xFF, 0x0, 0x0); } void changeViz(void) { currentViz = (currentViz + 1) % VIZUALIZATIONS; } void setup() { FastLED.addLeds(pixels, NUM_LEDS); FastLED.setBrightness(255); for (int i = 0; i < NUM_LEDS; i++) pixels[i] = CRGB(0, 0, 0); FastLED.show(); viz[0] = &viz1; viz[1] = &viz2; pinMode(INTR_PIN, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(INTR_PIN), changeViz, FALLING); } void loop() { (*viz[currentViz])(offset); FastLED.show(); delay(100); offset++; }