Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Blink shirt LEDs with a sequence and timing that suggests a terminal cursor.
#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