Arduino Starbucks Neopixel Name Badge
...for a friend(s).



Ingredients
Starbucks Name Badge (Blank)
Arduino Nano
Neopixel Strip (8)
Toggle Switch
3.7 LiPo Battery
Molex 51021 Female Connector
220 ohm Resistor
10uf Capacitor
Water Bottle (Diffused Plastic)



Notation(s)
1. First build utilized (2) 3V coin cells which ran the (8) Neopixels for approximately 2 hours before stalling the code for roughly (4) hours: https://www.reddit.com/r/starbucks/comments/d54fus/im_a_robotics_engineering_teacher_in_addition_to/
2. Shd an ATTiny85, Micro or Trinket magically appear dot dot dot a Nano is what was on hand.
3. Testing LiPo (720mAh) battery life --> so far 7+ hours...

Double Mochacodea
#include <FastLED.h>

FASTLED_USING_NAMESPACE

#define DATA_PIN 5
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define NUM_LEDS 8
CRGB leds[NUM_LEDS];

#define BRIGHTNESS 50
#define FRAMES_PER_SECOND 100

void setup() {
delay(1000);
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
}

typedef void (*SimplePatternList[])();
SimplePatternList gPatterns = { rainbowWithGlitter, confetti, sinelon, juggle, sparkle_go};

uint8_t gCurrentPatternNumber = 0;
uint8_t gHue = 0;

void loop()
{
gPatterns[gCurrentPatternNumber]();
FastLED.show();
FastLED.delay(1000 / FRAMES_PER_SECOND);
EVERY_N_MILLISECONDS( 20 ) {
gHue++;
}
EVERY_N_SECONDS( 10 ) {
nextPattern();
}
}

#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))

void nextPattern() {
gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
}

void rainbow()
{
fill_rainbow( leds, NUM_LEDS, gHue, 7);
}

void rainbowWithGlitter() {
rainbow();
addGlitter(80);
}

void addGlitter( fract8 chanceOfGlitter) {
if ( random8() < chanceOfGlitter) {
leds[ random16(NUM_LEDS) ] += CRGB::White;
}
}

void confetti() {
fadeToBlackBy( leds, NUM_LEDS, 10);
int pos = random16(NUM_LEDS);
leds[pos] += CHSV( gHue + random8(64), 200, 255);
}

void sinelon() {
fadeToBlackBy( leds, NUM_LEDS, 20);
int pos = beatsin16( 13, 0, NUM_LEDS - 1 );
leds[pos] += CHSV( gHue, 255, 192);
}

void juggle() {
fadeToBlackBy( leds, NUM_LEDS, 20);
byte dothue = 0;
for ( int i = 0; i < 8; i++) {
leds[beatsin16( i + 7, 0, NUM_LEDS - 1 )] |= CHSV(dothue, 200, 255);
dothue += 32;
}
}

void sparkle_go() {
Sparkle(0x00, 0x00, 0xff, 10);
}

void Sparkle(byte red, byte green, byte blue, int SpeedDelay) {
for (int i = 0; i < 20; i++) {
int Pixel = random(NUM_LEDS);
setPixel(Pixel, red, green, blue);
showStrip();
delay(SpeedDelay);
setPixel(Pixel, 0, 0, 0);
}
}

void fadeToBlack(int ledNo, byte fadeValue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
uint32_t oldColor;
uint8_t r, g, b;
int value;

oldColor = strip.getPixelColor(ledNo);
r = (oldColor & 0x00ff0000UL) >> 16;
g = (oldColor & 0x0000ff00UL) >> 8;
b = (oldColor & 0x000000ffUL);

r = (r <= 10) ? 0 : (int) r - (r * fadeValue / 256);
g = (g <= 10) ? 0 : (int) g - (g * fadeValue / 256);
b = (b <= 10) ? 0 : (int) b - (b * fadeValue / 256);

strip.setPixelColor(ledNo, r, g, b);
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[ledNo].fadeToBlackBy( fadeValue );
#endif
}

void showStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
FastLED.show();
#endif
}

void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[Pixel].r = red;
leds[Pixel].g = green;
leds[Pixel].b = blue;
#endif
}

void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
}
showStrip();
}

@pkvi
"...may not meet professional standards."
12,138 miters
5 miters today
202 tenons
Subscribe