Menu
Index
Engineering
Entertainment
Literature
Miscellaneous
Contact
Search
tiktok.com/@pkvi.xyz
buymeacoffee.com/pkvi
scored.co/u/pkvi_halfkdeltaxsq
Miter
Why Ayh?
Miter
@pkvi
"...may not meet professional standards."
320 miters
122 tenons
Subscribe
0.00144
Arduino Starbucks Neopixel Name Badge


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)



  1. #include <FastLED.h>
  2. FASTLED_USING_NAMESPACE
  3. #define DATA_PIN 5
  4. #define LED_TYPE WS2812B
  5. #define COLOR_ORDER GRB
  6. #define NUM_LEDS 8
  7. CRGB leds[NUM_LEDS];
  8. #define BRIGHTNESS 50
  9. #define FRAMES_PER_SECOND 100
  10. void setup() {
  11. delay(1000);
  12. FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  13. FastLED.setBrightness(BRIGHTNESS);
  14. }
  15. typedef void (*SimplePatternList[])();
  16. SimplePatternList gPatterns = { rainbowWithGlitter, confetti, sinelon, juggle, sparkle_go};
  17. uint8_t gCurrentPatternNumber = 0;
  18. uint8_t gHue = 0;
  19. void loop()
  20. {
  21. gPatterns[gCurrentPatternNumber]();
  22. FastLED.show();
  23. FastLED.delay(1000 / FRAMES_PER_SECOND);
  24. EVERY_N_MILLISECONDS( 20 ) {
  25. gHue++;
  26. }
  27. EVERY_N_SECONDS( 10 ) {
  28. nextPattern();
  29. }
  30. }
  31. #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
  32. void nextPattern() {
  33. gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
  34. }
  35. void rainbow()
  36. {
  37. fill_rainbow( leds, NUM_LEDS, gHue, 7);
  38. }
  39. void rainbowWithGlitter() {
  40. rainbow();
  41. addGlitter(80);
  42. }
  43. void addGlitter( fract8 chanceOfGlitter) {
  44. if ( random8() < chanceOfGlitter) {
  45. leds[ random16(NUM_LEDS) ] += CRGB::White;
  46. }
  47. }
  48. void confetti() {
  49. fadeToBlackBy( leds, NUM_LEDS, 10);
  50. int pos = random16(NUM_LEDS);
  51. leds[pos] += CHSV( gHue + random8(64), 200, 255);
  52. }
  53. void sinelon() {
  54. fadeToBlackBy( leds, NUM_LEDS, 20);
  55. int pos = beatsin16( 13, 0, NUM_LEDS - 1 );
  56. leds[pos] += CHSV( gHue, 255, 192);
  57. }
  58. void juggle() {
  59. fadeToBlackBy( leds, NUM_LEDS, 20);
  60. byte dothue = 0;
  61. for ( int i = 0; i < 8; i++) {
  62. leds[beatsin16( i + 7, 0, NUM_LEDS - 1 )] |= CHSV(dothue, 200, 255);
  63. dothue += 32;
  64. }
  65. }
  66. void sparkle_go() {
  67. Sparkle(0x00, 0x00, 0xff, 10);
  68. }
  69. void Sparkle(byte red, byte green, byte blue, int SpeedDelay) {
  70. for (int i = 0; i < 20; i++) {
  71. int Pixel = random(NUM_LEDS);
  72. setPixel(Pixel, red, green, blue);
  73. showStrip();
  74. delay(SpeedDelay);
  75. setPixel(Pixel, 0, 0, 0);
  76. }
  77. }
  78. void fadeToBlack(int ledNo, byte fadeValue) {
  79. #ifdef ADAFRUIT_NEOPIXEL_H
  80. // NeoPixel
  81. uint32_t oldColor;
  82. uint8_t r, g, b;
  83. int value;
  84. oldColor = strip.getPixelColor(ledNo);
  85. r = (oldColor & 0x00ff0000UL) >> 16;
  86. g = (oldColor & 0x0000ff00UL) >> 8;
  87. b = (oldColor & 0x000000ffUL);
  88. r = (r <= 10) ? 0 : (int) r - (r * fadeValue / 256);
  89. g = (g <= 10) ? 0 : (int) g - (g * fadeValue / 256);
  90. b = (b <= 10) ? 0 : (int) b - (b * fadeValue / 256);
  91. strip.setPixelColor(ledNo, r, g, b);
  92. #endif
  93. #ifndef ADAFRUIT_NEOPIXEL_H
  94. // FastLED
  95. leds[ledNo].fadeToBlackBy( fadeValue );
  96. #endif
  97. }
  98. void showStrip() {
  99. #ifdef ADAFRUIT_NEOPIXEL_H
  100. // NeoPixel
  101. strip.show();
  102. #endif
  103. #ifndef ADAFRUIT_NEOPIXEL_H
  104. // FastLED
  105. FastLED.show();
  106. #endif
  107. }
  108. void setPixel(int Pixel, byte red, byte green, byte blue) {
  109. #ifdef ADAFRUIT_NEOPIXEL_H
  110. // NeoPixel
  111. strip.setPixelColor(Pixel, strip.Color(red, green, blue));
  112. #endif
  113. #ifndef ADAFRUIT_NEOPIXEL_H
  114. // FastLED
  115. leds[Pixel].r = red;
  116. leds[Pixel].g = green;
  117. leds[Pixel].b = blue;
  118. #endif
  119. }
  120. void setAll(byte red, byte green, byte blue) {
  121. for(int i = 0; i < NUM_LEDS; i++ ) {
  122. setPixel(i, red, green, blue);
  123. }
  124. showStrip();
  125. }