GlowHood

From Noisebridge
Revision as of 18:32, 16 October 2014 by Six26 (talk | contribs) (Hardware)
Jump to: navigation, search

Software

Blinkadelic fabrikz


Hardware

LEDs

WS2812B's (144/m)

http://www.adafruit.com/products/1507

1-9 $59.95 / Meter 10-99 $53.96 100+ $47.96


http://www.aliexpress.com/item/1m-4m-5m-WS2812B-Smart-led-pixel-strip-Black-White-PCB-30-60-144-leds-m/2036819167.html

$30.28 / Meter


http://www.aliexpress.com/item/Free-shipping-dc-5v-black-pcb-5050-smd-rgb-ws2812b-144-pixel-m-pixel-led-strip/1519141639.html

US $32.66 / Meter (w/shipping)


http://www.aliexpress.com/item/Non-Waterproof-144-Pixels-M-WS2812B-Chip-White-PCB-WS2811-IC-Digital-RGB-LED-Strip-Light/1655210597.html

$29.88 / Meter


http://www.aliexpress.com/item/waterproof-ip67-dc-5v-magic-dream-color-individually-addressable-ws2811-ws2812-ws2812b-144-pixel-m-led/1939650965.html

$27.24 / Meter


http://www.alibaba.com/product-detail/ws2801-ws2811-ws2812b-144-led-pixel_60070919436.html


http://www.alibaba.com/product-detail/ws2812B-led-strip-144-leds-and_1423553451.html


http://www.alibaba.com/product-detail/Hot-sales-ws2812b-144-RGB-led_1890938012.html


MCUs

Code

Twinkle`Z w/Button Button Hack

#include "FastLED.h"

// How many leds in your strip?
#define NUM_LEDS 72

#define NUM_TWINK 8

// Delay between cycles
#define LOOP_DELAY 50

// Strip Data In (DI)
#define DATA_PIN 11

#define HOLD_THRESHOLD 200
#define STANDBY_TIME 5000

// Define the array of leds
CRGB leds[NUM_LEDS];


int twinklePos[NUM_TWINK];
byte twinkleHue[NUM_TWINK];
byte twinkleVal[NUM_TWINK];

unsigned long lastTime = 0;
unsigned long holdTime = 0;

boolean standbyMode = false;

void setup() {
  pinMode(13, OUTPUT);
  
  Serial.begin(9600);
  
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  
  FastLED.setBrightness(96);
  
  for (int i = 0; i < NUM_TWINK; i++)
  {
    twinklePos[i] = 0;
    twinkleHue[i] = 0;
    twinkleVal[i] = 0;
  }
  
  delay(200);
  
}

void loop() {
  // Twinkle`Z
  
  for (int j = 0; j < NUM_TWINK; j++)
  {
    if (twinkleVal[j] == 0)
    {
      int led = random(0, NUM_LEDS);
    
      twinklePos[j] = led;
      twinkleHue[j] = random(0, 255);
      twinkleVal[j] = random(32, 255);
      
    } else {
      twinkleHue[j] += random(-32, 32);
      twinkleVal[j] += random(-32, 8);
      if (twinkleVal[j] <= 32)
      {
        // Done
        twinkleVal[j] = 0;
      }
    }
  }
  
  int button = analogRead(A0);
  
  unsigned long now = millis();
  
  boolean onOff = button < 96 || button > 927;
  
  if (onOff)
    lastTime = now;
    
  if (now - holdTime > STANDBY_TIME)
  {
    // Change mode
    if (!standbyMode)
    {
      for (int l = 0; l < NUM_LEDS; l++)
      {
        leds[l] = CHSV(0, 0, 0);
        FastLED.show(); 
      }
    }
    standbyMode = !standbyMode;
    holdTime = now;
  }
  
  if (onOff != digitalRead(13) == HIGH)
  {
    if (onOff)
    {
      holdTime = now;
      digitalWrite(13, HIGH);
    }
    else if (now - lastTime > HOLD_THRESHOLD)
    {
      digitalWrite(13, LOW);
    }
  }
  
  for (int i = 0; i < NUM_TWINK; i++)
  {
    leds[twinklePos[i]] = CHSV(twinkleHue[i], onOff ? 0 : 255, twinkleVal[i]);
  }
  
  if (!standbyMode)
    FastLED.show();
  
  Serial.println(String(button));
  
  if (digitalRead(13) == HIGH)
  {
    delay(LOOP_DELAY / 5);
  } else {
    holdTime = now;
    delay(LOOP_DELAY);
  }
  
  // Serial.println(String(standbyMode) + ", " + String(onOff) + ", " + String(now - holdTime));
}


Multi-mode demo with Serial

/*
*  Serial control interface for LED Strip
*
*    Updated: 20140921
*
*    Command Summary:
*      MODE0 == Auto (Rainbeau)
*      MODE1 == Off
*      MODE2 == Remote (PC Control)
*      HH..H == Sequence of Hue values to apply to LEDs
*        Note: Set "MODE2" before sending hues
*      S     == Set saturation
*      MODE3 == Center Peak Rainbeau
*      MODE4 == Center Peak Pastel
*/

#include "FastLED.h"

// How many leds in your strip?
#define NUM_LEDS 72

// Spacing between pixel/color
#define HSV_PAD 4

// Delay between cycles
#define LOOP_DELAY 50

// Strip Data In (DI)
#define DATA_PIN 11

// Define the array of leds
CRGB leds[NUM_LEDS];

float counter = 0;
byte count = 0;

byte mode = 4;
byte hues[NUM_LEDS];
byte sat = 255;      // Saturation 0-255

String inputString = "";

void setup() { 
  pinMode(13, OUTPUT);
  
  for (int i = 0; i < NUM_LEDS; i++)
  {
    hues[i] = 0;
  }
  
  FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
  
  // Max brightness 0-255 (64 ~< 100ma for 12 LEDs)
  FastLED.setBrightness(64);
  
  Serial.begin(9600);
  Serial.setTimeout(50);
  
  delay(200);
}

void loop() {
  int i;
  int v;
  float p;
  
  if (mode == 0)
  {
    // Rainbeau
    for (i = 0; i < NUM_LEDS; i++)
    {
      leds[i] = CHSV(count + (i * HSV_PAD), sat, 255);
    }
    FastLED.show();
    count++;
    
    delay(LOOP_DELAY);
  }
  else if (mode == 1)
  {
    // Off
    for (i = 0; i < NUM_LEDS; i++)
    {
      leds[i] = CRGB(0, 0, 0);
    }
    FastLED.show();
    
    delay(LOOP_DELAY);
  }
  else if (mode == 2)
  {
    // Remote +hex
  }
  else if (mode == 3)
  {
    // Rainbeau
    for (i = 0; i < NUM_LEDS; i++)
    {
      // variable position dimming
      // Set 'p' to 0.0 - 1.0 so the ends are 0.0 and the center is 1.0
      p = (((NUM_LEDS / 2) - abs(i - (NUM_LEDS / 2.0)))) / (NUM_LEDS / 2.0);
      v = min(255, round(p * 255.0) + 64);

      // sin function added for oscillating color change
      counter += 0.000001337;
      count = sin(counter * 3.14 * 180) * 255 + (i * HSV_PAD);
      leds[i] = CHSV(count, sat, v);// - (v/1.5), v);
    }
    FastLED.show();
    count++;
    
    delay(LOOP_DELAY);
  }
  else if (mode == 4)
  {
    // Rainbeau
    for (i = 0; i < NUM_LEDS; i++)
    {
      // variable position dimming
      // Set 'p' to 0.0 - 1.0 so the ends are 0.0 and the center is 1.0
      p = (((NUM_LEDS / 2) - abs(i - (NUM_LEDS / 2.0)))) / (NUM_LEDS / 2.0);
      v = min(255, round(p * 255.0) + 64);
      
      // sin function added for oscillating color change
      counter += 0.000001337;
      count = sin(counter * 3.14 * 180) * 255 + (i * HSV_PAD);
      leds[i] = CHSV(count, sat - (v/1.5), v);
    }
    FastLED.show();
    count++;
    
    delay(LOOP_DELAY);
  }
}

void updateHues() {
  for (int i = 0; i < NUM_LEDS; i++)
  {
    leds[i] = CHSV(hues[i], 255, 255);
  }
  FastLED.show();
  
  // Toggle onboard LED
  digitalWrite(13, !digitalRead(13));
}

void serialEvent() {
  byte byteCount = 0;
  byte data;
  
  inputString = "";
  
  while(Serial.available())
  {
    data = Serial.read();
    inputString += (char)data;
    if (byteCount < NUM_LEDS)
    {
      hues[byteCount++] = byte(data + 90);
    }
    
    // Catch pending bits
    if (!Serial.available())
      delay(20);
  }
  
  if (inputString == "MODE0")
  {
    mode = 0;
  }
  else if (inputString == "MODE1")
  {
    mode = 1;
  }
  else if (inputString == "MODE2")
  {
    mode = 2;
  }
  else if (inputString == "MODE3")
  {
    mode = 3;
  }
  else if (inputString == "MODE4")
  {
    mode = 4;
  }
  else if (inputString.length() == NUM_LEDS)
  {
    updateHues();
  }
  else if (inputString.length() == 1)
  {
    sat = data;
  }
}