Skip to content

Instantly share code, notes, and snippets.

@apetrone
Created February 14, 2014 07:29
Show Gist options
  • Save apetrone/8997116 to your computer and use it in GitHub Desktop.
Save apetrone/8997116 to your computer and use it in GitHub Desktop.
Firmware for the LED Heart, Valentine's Day 2014
/*
Date: February 2014
Author: Adam Petrone
Valentine's Day LED Heart
*/
#include <Adafruit_NeoPixel.h>
#include <avr/power.h>
const uint8_t NUM_PIXELS = 6;
const long COLOR_CHANGE_DELAY_MSEC = 15;
Adafruit_NeoPixel left = Adafruit_NeoPixel(NUM_PIXELS, 2);
Adafruit_NeoPixel right = Adafruit_NeoPixel(NUM_PIXELS, 4);
uint8_t wheel_offset = 0;
void fill_strip(Adafruit_NeoPixel& pixels, uint32_t color)
{
for(uint8_t p = 0; p < NUM_PIXELS; ++p)
{
pixels.setPixelColor(p, color);
}
}
void incrementally_fill_strip(Adafruit_NeoPixel & pixels, uint32_t color, uint8_t delay_msec, int8_t travel_dir)
// travel_dir determines which direction the strip is filled
{
int8_t start = 0;
int8_t max_pixels = NUM_PIXELS;
if (travel_dir < 0)
{
start = NUM_PIXELS-1;
max_pixels = -1;
}
for(int8_t p = start; p != max_pixels; p += travel_dir)
{
pixels.setPixelColor(p, color);
pixels.show();
delay(delay_msec);
}
}
void setup()
{
if (F_CPU == 16000000)
{
clock_prescale_set(clock_div_1);
}
left.begin();
right.begin();
fill_strip(left, left.Color(0,0,0));
fill_strip(right, right.Color(0,0,0));
left.show();
right.show();
left.setBrightness(16);
right.setBrightness(16);
incrementally_fill_strip(left, left.Color(0,255,0), 250, 1);
incrementally_fill_strip(right, right.Color(0,255,0), 250, 1);
left.setBrightness(64);
right.setBrightness(64);
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
// (This code is lifted from one of Adafruit's examples)
uint32_t Wheel(Adafruit_NeoPixel & pixels, byte WheelPos) {
if(WheelPos < 85) {
return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
void loop()
{
for(uint8_t p = 0; p < NUM_PIXELS; ++p)
{
left.setPixelColor(p, Wheel(left, wheel_offset));
right.setPixelColor(p, Wheel(right, 255-wheel_offset));
left.show();
right.show();
delay(COLOR_CHANGE_DELAY_MSEC);
}
++wheel_offset;
if (wheel_offset == 255)
{
wheel_offset = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment