Alison Yang
Published

Wearable - DIY LED Earrings

Are you looking for a creative and fashion accessory? Let's make it!

BeginnerWork in progress4 hours273
Wearable - DIY LED Earrings

Things used in this project

Hardware components

Seeed Studio XIAO SAMD21 (Pre-Soldered) - Seeeduino XIAO
Seeed Studio XIAO SAMD21 (Pre-Soldered) - Seeeduino XIAO
×2

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Seeed Studio Grove - Universal 4 Pin Buckled 5cm Cable (5 PCs Pack)
Pink Strings
LEDs
Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Code

LED Earrings

Arduino
#include <Adafruit_NeoPXL8.h>

 #define NUM_LEDS    7      // NeoPixels PER STRAND, total number is 8X this!
// #define COLOR_ORDER NEO_GRB // NeoPixel color format (see Adafruit_NeoPixel)

int8_t pins[8] = { 6, 7, 9, 8, 13, 12, 11, 10 };
#define COLOR_ORDER NEO_GRB


// Here's the global constructor as explained near the start:
Adafruit_NeoPXL8 leds(NUM_LEDS, pins, COLOR_ORDER);
//Adafruit_NeoPXL8 leds(ledsPerPin, pins, COLOR_ORDER);
// For this demo we use a table of 8 hues, one for each strand of pixels:
static uint8_t colors[8][3] = {
  255,   0,   0, // Row 0: Red
  255, 160,   0, // Row 1: Orange
  255, 255,   0, // Row 2: Yellow
    0, 255,   0, // Row 3: Green
    0, 255, 255, // Row 4: Cyan
    0,   0, 255, // Row 5: Blue
  192,   0, 255, // Row 6: Purple
  255,   0, 255  // Row 7: Magenta
};

// setup() runs once on program startup:
void setup() {
  // Start NeoPXL8. If begin() returns false, either an invalid pin list
  // was provided, or requested too many pixels for available RAM.
  if (!leds.begin()) {
    // Blink the onboard LED if that happens.
    pinMode(LED_BUILTIN, OUTPUT);
    for (;;) digitalWrite(LED_BUILTIN, (millis() / 500) & 1);
  }

  // Otherwise, NeoPXL8 is now running, we can continue.

  leds.setBrightness(32); // Tone it down, NeoPixels are BRIGHT!

  // Cycle all pixels red/green/blue on startup. If you see a different
  // sequence, COLOR_ORDER doesn't match your particular NeoPixel type.
  // If you get a jumble of colors, you're using RGBW NeoPixels with an
  // RGB order. Try different COLOR_ORDER values until code and hardware
  // are in harmony.
  for (uint32_t color = 0xFF0000; color > 0; color >>= 8) {
    leds.fill(color);
    leds.show();
    delay(100);
  }

  // Light each strip in sequence. This helps verify the mapping of pins to
  // a physical LED installation. If strips flash out of sequence, you can
  // either re-wire, or just change the order of the pins[] array.
  for (int i=0; i<8; i++) {
    if (pins && (pins[i] < 0)) continue; // No pixels on this pin
    leds.fill(0);
    uint32_t color = leds.Color(0,255,255);
    leds.fill(color, i * NUM_LEDS, NUM_LEDS);
    leds.show();
    delay(500);
  }

  // The other examples do not include the above two tests. It's assumed at
  // that point that your code and hardware are confirmed in sync, making
  // these redundant.
}

// loop() runs over and over indefinitely. We use this to render each frame
// of a repeating animation cycle based on elapsed time:
void loop() {
  uint32_t now = millis(); // Get time once at start of each frame
  for(uint8_t r=0; r<8; r++) { // For each row...
    for(int p=0; p<NUM_LEDS; p++) { // For each pixel of row...
      leds.setPixelColor(r * NUM_LEDS + p, rain(now, r, p));
    }
  }
  leds.show();
}

// Given current time in milliseconds, row number (0-7) and pixel number
// along row (0 - (NUM_LEDS-1)), first calculate brightness (b) of pixel,
// then multiply row color by this and run it through NeoPixel librarys
// gamma-correction table.
uint32_t rain(uint32_t now, uint8_t row, int pixelNum) {
  uint8_t frame = now / 4; // uint8_t rolls over for a 0-255 range
  uint16_t b = 256 - ((frame - row * 32 + pixelNum * 256 / NUM_LEDS) & 0xFF);
  return leds.Color(leds.gamma8((colors[row][0] * b) >> 8),
                    leds.gamma8((colors[row][1] * b) >> 8),
                    leds.gamma8((colors[row][2] * b) >> 8));
}

Credits

Alison Yang

Alison Yang

2 projects • 38 followers
Maker...

Comments