Skip to content

Instantly share code, notes, and snippets.

@mexitalian
Created March 7, 2020 14:06
Show Gist options
  • Save mexitalian/77c83b9171b0db8766878da6fad72c24 to your computer and use it in GitHub Desktop.
Save mexitalian/77c83b9171b0db8766878da6fad72c24 to your computer and use it in GitHub Desktop.
Basic snake ping ponging along a 30 led strip
#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