I reworked the code and the article for Project Ouroboros. You can see the update by clicking here. When I originally wrote the article in 2011 a USBasp programmer was around $6 on eBay, but now you can buy one in 2019 for about $1.50; pretty amazing.
Here’s some code I wrote for the USBasp programmer board I played around with in Project Ouroboros. A bit surprisingly I had no trouble powering a WS2812B strip with just 3.3V. If you run this code on a 5V board you should change LED_STRIP_VOLTAGE
to 5
, although it’s not strictly necessary because that number doesn’t actually control the voltage. If you do change it to 5
then the power allotted to the LEDs will increase and they will get brighter. I tested the board with 100mW for the LEDs and I had no problems.
#include <FastLED.h> #define NUM_LEDS 8 #define DATA_PIN 12 // MISO pin #define FRAMES_PER_SECOND 125 #define LED_STRIP_VOLTAGE 3.3 #define LED_STRIP_MILLIAMPS 20 CRGB leds[NUM_LEDS]; void setup() { FastLED.setMaxPowerInVoltsAndMilliamps(LED_STRIP_VOLTAGE, LED_STRIP_MILLIAMPS); FastLED.setCorrection(TypicalSMD5050); FastLED.addLeds(leds, NUM_LEDS); pinMode(14, OUTPUT); // green LED, LOW == ON digitalWrite(14, HIGH); // turn green LED off } void blink() { static uint8_t i = 0; uint8_t brightness_bool = i++/128; digitalWrite(14, !brightness_bool); // green on board LED, LOW is ON leds[0] = CHSV(0, 255, 255*brightness_bool); } void breath() { const uint8_t min_brightness = 2; static uint8_t delta = 0; // goes up to 255 then overflows back to 0 // for the LEDs in the current state setting the brightness higher than max_brightness will not actually increase the brightness displayed uint8_t max_brightness = calculate_max_brightness_for_power_vmA(leds, NUM_LEDS, 255, LED_STRIP_VOLTAGE, LED_STRIP_MILLIAMPS); uint8_t b = scale8(triwave8(delta), max_brightness-min_brightness)+min_brightness; FastLED.setBrightness(b); delta++; } void loop() { static uint8_t dynamic_hue = 0; //blink(); //fill_solid(leds, NUM_LEDS, CHSV(dynamic_hue, 255, 255)); fill_rainbow(leds, NUM_LEDS, dynamic_hue, 21); //breath(); // breath isn't meant to be run by itself. combine it with one of the functions above. EVERY_N_MILLISECONDS(100) { dynamic_hue+=6; } FastLED.delay(1000/FRAMES_PER_SECOND); }
Code
Project Ouroboros GitHub Repo