Created
July 11, 2020 14:53
-
-
Save programmarchy/e253b8a1ffbdef139a7bae2c51220fd4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <FastLED.h> | |
#define LED_PIN 7 | |
#define NUM_LEDS 240 | |
CRGB leds[NUM_LEDS]; | |
int offset = 0; | |
void setup() { | |
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS); | |
} | |
void rainbow_loop() { | |
for (int i = 0; i < NUM_LEDS ; ++i) { | |
switch ((i + offset) % 7) { | |
case 0: | |
leds[i] = CRGB(255, 0, 0); | |
break; | |
case 1: | |
leds[i] = CRGB(255, 165, 0); | |
break; | |
case 2: | |
leds[i] = CRGB(255, 255, 0); | |
break; | |
case 3: | |
leds[i] = CRGB(0, 255, 0); | |
break; | |
case 4: | |
leds[i] = CRGB(0, 0, 255); | |
break; | |
case 5: | |
leds[i] = CRGB(75, 0, 130); | |
break; | |
case 6: | |
leds[i] = CRGB(238, 130, 238); | |
break; | |
} | |
} | |
} | |
void candy_cane_loop() { | |
for (int i = 0; i < NUM_LEDS ; ++i) { | |
switch ((i + offset) % 3) { | |
case 0: | |
leds[i] = CRGB(255, 255, 255); | |
break; | |
case 1: | |
leds[i] = CRGB(255, 0, 0); | |
break; | |
case 2: | |
leds[i] = CRGB(255, 0, 0); | |
break; | |
} | |
} | |
} | |
void crazy_loop() { | |
for (int i = 0; i < NUM_LEDS ; ++i) { | |
leds[i] = CRGB(random(255), random(255), random(255)); | |
} | |
} | |
int snake_length = 10; | |
int mouse_caught = 0; | |
void snake_loop() { | |
for (int i = 0; i < NUM_LEDS ; ++i) { | |
if (i > offset && i < offset + snake_length) { | |
if (mouse_caught == 1 && i == offset + snake_length / 2) { | |
leds[i] = CRGB::Red; | |
} else { | |
leds[i] = CRGB::Green; | |
} | |
} else if (i == offset) { | |
leds[i] = CRGB::Blue; // Tail | |
} else if (i == offset + snake_length) { | |
leds[i] = CRGB::Blue; // Head | |
} else if (mouse_caught == 0 && i == offset + snake_length + 5) { | |
leds[i] = CRGB::Red; | |
} else { | |
leds[i] = CRGB::Black; | |
} | |
} | |
if (offset > 100) { | |
mouse_caught = 1; | |
} | |
} | |
void otto_loop() { | |
for (int i = 0; i < NUM_LEDS; ++i) { | |
leds[i] = CRGB::White; | |
} | |
} | |
void loop() { | |
// rainbow_loop(); | |
// candy_cane_loop(); | |
// crazy_loop(); | |
snake_loop(); | |
// otto_loop(); | |
FastLED.show(); | |
delay(20); | |
offset += 1; | |
if (offset >= NUM_LEDS) { | |
offset = 0; | |
mouse_caught = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment