Created
March 7, 2020 14:06
-
-
Save mexitalian/77c83b9171b0db8766878da6fad72c24 to your computer and use it in GitHub Desktop.
Basic snake ping ponging along a 30 led strip
This file contains hidden or 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 <Arduino.h> | |
#include <FastLED.h> | |
#define NUM_LEDS 30 | |
#define MILLIS_PER_FRAME 33 | |
#define FRAMES_PER_SECOND 30; | |
CRGB leds[NUM_LEDS]; | |
int frame = 0; | |
bool forward = true; | |
void allColor(CRGB color) { | |
for(int i = NUM_LEDS; i--;) { | |
leds[i] = color; | |
} | |
} | |
void clear() { | |
allColor(CRGB::Black); | |
} | |
void white() { | |
allColor(CRGB::White); | |
} | |
void snake(int start, int length) { | |
for(int i = 0; i < length; i++) { | |
leds[i + start] = CRGB::White; FastLED.show(); | |
} | |
} | |
void setup() { | |
FastLED.addLeds<DOTSTAR>(leds, NUM_LEDS); | |
} | |
void loop() { | |
clear(); | |
FastLED.show(); | |
snake(frame, 3); | |
delay(MILLIS_PER_FRAME); | |
if (forward) frame++; | |
if (!forward) frame--; | |
if (frame == 30 - 3 || frame == 0) forward = !forward; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment