Created
June 26, 2014 04:18
-
-
Save yomimono/9e907a9475014e47fb5d to your computer and use it in GitHub Desktop.
Blink shirt LEDs with a sequence and timing that suggests a terminal cursor.
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 <Adafruit_NeoPixel.h> | |
#define PIN 6 | |
#define PIXELS 7 | |
#define MAX_PERTURBATION 3 | |
#define RANDOM_SOURCE 10 | |
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXELS, PIN, NEO_GRB + NEO_KHZ800); | |
void setup() { | |
strip.begin(); | |
strip.show(); | |
randomSeed(analogRead(RANDOM_SOURCE)); | |
} | |
void loop() { | |
colorWipe(strip.Color(63, 63, 63), 5, 512); | |
for(int i = 0; i < PIXELS; i++) { | |
strip.setPixelColor(i, 0); | |
} | |
strip.show(); | |
} | |
uint16_t perturb(uint16_t value) { | |
uint16_t amount; | |
amount = random(0, MAX_PERTURBATION); | |
return value - amount; | |
} | |
uint16_t nextPixel(uint16_t pixel) { | |
if (pixel < 2) return pixel+1; | |
if (pixel == 2) return PIXELS - 1; | |
if (pixel == 3) return 0; | |
return pixel - 1; | |
} | |
// Fill the dots one after the other with a color | |
void colorWipe(uint32_t c, uint16_t cycle_wait, uint16_t cursor_wait) { | |
int pixel = 0; | |
do { | |
strip.setPixelColor(pixel, c); | |
strip.show(); | |
for(int i = 0; i < perturb(cycle_wait); i++) { | |
//blink cursor | |
strip.setPixelColor(pixel, 0); | |
strip.show(); | |
delay(cursor_wait); | |
strip.setPixelColor(pixel, c); | |
strip.show(); | |
delay(cursor_wait); | |
} | |
pixel = nextPixel(pixel); | |
} while (pixel != 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment