Skip to content

Commit

Permalink
Add dependent library
Browse files Browse the repository at this point in the history
  • Loading branch information
Jade Meskill and Roy van de Water authored and Integrum committed Dec 5, 2013
1 parent b8875d8 commit e94281a
Show file tree
Hide file tree
Showing 69 changed files with 21,231 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/BlinkyTape_Arduino/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*\.DS_Store
87 changes: 87 additions & 0 deletions lib/BlinkyTape_Arduino/Animation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include "Animation.h"

Animation::Animation() {
init(0, NULL, ENCODING_RGB24, 0);
}

Animation::Animation(uint16_t frameCount,
const prog_uint8_t* frameData,
const uint8_t encoding,
const uint8_t ledCount)
{
init(frameCount, frameData, encoding, ledCount);
reset();
}

void Animation::init(uint16_t frameCount,
const prog_uint8_t* frameData,
const uint8_t encoding,
const uint8_t ledCount)
{
m_frameCount = frameCount;
m_frameData = const_cast<prog_uint8_t*>(frameData);
m_encoding = encoding;
m_ledCount = ledCount;
reset();
}

void Animation::reset() {
m_frameIndex = 0;
currentFrameData = m_frameData;
}

void Animation::draw(struct CRGB strip[]) {
switch(m_encoding) {
case ENCODING_RGB24:
drawNoEncoding(strip);
break;
case ENCODING_RGB565_RLE:
draw16bitRLE(strip);
break;
}
};

void Animation::drawNoEncoding(struct CRGB strip[]) {
currentFrameData = m_frameData + m_frameIndex*m_ledCount*3;

for(uint8_t i = 0; i < m_ledCount; i+=1) {
strip[i] = CRGB(pgm_read_byte(currentFrameData + i*3 ),
pgm_read_byte(currentFrameData + i*3 + 1),
pgm_read_byte(currentFrameData + i*3 + 2));
}

LEDS.show();

m_frameIndex = (m_frameIndex + 1)%m_frameCount;
}

void Animation::draw16bitRLE(struct CRGB strip[]) {

// Read runs of RLE data until we get enough data.
uint8_t count = 0;
while(count < m_ledCount) {
// TODO: Test if we're going to read from an invalid location?
uint8_t run_length = 0x7F & pgm_read_byte(currentFrameData);
uint8_t upperByte = pgm_read_byte(currentFrameData + 1);
uint8_t lowerByte = pgm_read_byte(currentFrameData + 2);

uint8_t r = ((upperByte & 0xF8) );
uint8_t g = ((upperByte & 0x07) << 5)
| ((lowerByte & 0xE0) >> 3);
uint8_t b = ((lowerByte & 0x1F) << 3);

for(uint8_t i = 0; i < run_length; i+=1) {
strip[count + i] = CRGB(r,g,b);
}

count += run_length;
currentFrameData += 3;
}

LEDS.show();

m_frameIndex = (m_frameIndex + 1)%m_frameCount;
if(m_frameIndex == 0) {
currentFrameData = m_frameData;
}
};
43 changes: 43 additions & 0 deletions lib/BlinkyTape_Arduino/Animation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef ANIMATION_H
#define ANIMATION_H

#include <Arduino.h>
#include <FastSPI_LED2.h>

#define ENCODING_RGB24 0
#define ENCODING_RGB565_RLE 1

class Animation {
private:
uint16_t m_frameCount;
prog_uint8_t* m_frameData;
uint8_t m_encoding;
uint8_t m_ledCount;

uint16_t m_frameIndex;
prog_uint8_t* currentFrameData;

void drawNoEncoding(struct CRGB strip[]);
void draw16bitRLE(struct CRGB strip[]);

public:
Animation();
Animation(uint16_t frameCount,
const prog_uint8_t* frameData,
const uint8_t encoding,
const uint8_t ledCount);

// Re-initialize the animation with new information
void init(uint16_t frameCount,
const prog_uint8_t* frameData,
const uint8_t encoding,
const uint8_t ledCount);

// Reset the animation
void reset();

// Draw the next frame of the animation
void draw(struct CRGB strip[]);
};

#endif
111 changes: 111 additions & 0 deletions lib/BlinkyTape_Arduino/examples/ColorSwirl/ColorSwirl.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#include <FastSPI_LED2.h>
#include <Animation.h>

#define LED_COUNT 60
struct CRGB leds[LED_COUNT];

#ifdef REVB // RevB boards have a slightly different pinout.

#define LED_OUT 5
#define BUTTON_IN 13
#define ANALOG_INPUT A11
#define IO_A 15

#else

#define LED_OUT 13
#define BUTTON_IN 10
#define ANALOG_INPUT A9
#define IO_A 7
#define IO_B 11

#endif

long last_time;

void setup()
{
Serial.begin(57600);

LEDS.addLeds<WS2811, LED_OUT, GRB>(leds, LED_COUNT);
LEDS.showColor(CRGB(0, 0, 0));
LEDS.setBrightness(93); // Limit max current draw to 1A
LEDS.show();

last_time = millis();
}


void color_loop() {
static uint8_t i = 0;
static int j = 0;
static int f = 0;
static int k = 0;
static int count;

static int pixelIndex;

for (uint8_t i = 0; i < LED_COUNT; i++) {
leds[i].r = 64*(1+sin(i/2.0 + j/4.0 ));
leds[i].g = 64*(1+sin(i/1.0 + f/9.0 + 2.1));
leds[i].b = 64*(1+sin(i/3.0 + k/14.0 + 4.2));

if ((millis() - last_time > 15) && pixelIndex <= LED_COUNT + 1) {
last_time = millis();
count = LED_COUNT - pixelIndex;
pixelIndex++;
}

// why is this per LED?
for (int x = count; x >= 0; x--) {
leds[x] = CRGB(0, 0, 0);
}

}
LEDS.show();

j = j + 1;
f = f + 1;
k = k + 2;
}

void serialLoop() {
static int pixelIndex;

while(true) {

if(Serial.available() > 2) {

uint8_t buffer[3]; // Buffer to store three incoming bytes used to compile a single LED color

for (uint8_t x=0; x<3; x++) { // Read three incoming bytes
uint8_t c = Serial.read();

if (c < 255) {
buffer[x] = c; // Using 255 as a latch semaphore
}
else {
LEDS.show();
pixelIndex = 0;
break;
}

if (x == 2) { // If we received three serial bytes
leds[pixelIndex] = CRGB(buffer[0], buffer[1], buffer[2]);
pixelIndex++;
}
}
}
}
}

void loop()
{
// If'n we get some data, switch to passthrough mode
if(Serial.available() > 0) {
serialLoop();
}

color_loop();
}

70 changes: 70 additions & 0 deletions lib/BlinkyTape_Arduino/examples/HelloBlinky/HelloBlinky.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include <FastSPI_LED2.h>
#include <Animation.h>

#define LED_COUNT 60 // BlinkyTape has 60 LEDs!
struct CRGB leds[LED_COUNT]; // this struct contains 60 CRGB values. This is where

#define PIN_BUTTON 10
#define PIN_IO_A 7
#define PIN_IO_B 11
#define PIN_SIGNAL 13
#define PIN_INPUT 10

int color_set = 0;

// first, let's get ready to blink using some FastSPI_LED2 routines
// take a look at the FastSPI_LED2 example called Fast2Dev for more usage info
void setup()
{
LEDS.addLeds<WS2811, PIN_SIGNAL, GRB>(leds, LED_COUNT); // this configures the BlinkyBoard - leave as is.
LEDS.showColor(CRGB(0, 0, 0)); // set the color for the strip all at once.
LEDS.setBrightness(0); // start out with LEDs off
LEDS.show(); // you'll always need to call this function to make your changes happen.
}

// set the color for all the LEDs based on the color code
void setcolor(int colorcode) {

for (int i = 0; i < LED_COUNT; i++) {
// instead of setting the color all at once we're going to step through each LED to show how to set them individually
switch(colorcode) {
// there are several ways to set colors. We're going to pass a CRGB here, but there are other methods.
// See the Fast2Dev example for the others
case 0: leds[i] = CRGB(i*3,0,0); break; // using the 'i' term will create a brightness gradient in active color

case 1: leds[i] = CRGB(0,i*3,0); break;

case 2: leds[i] = CRGB(0,0,i*3); break;
}
}
LEDS.show();
}

// we'll make the color fade in and out by setting the brightness
void pulse(int wait_time) {
// let's fade up by scaling the brightness - in general, brightness shouldn't go above 93, so the strip won't draw too much power.
// Oh, and 93 is plenty bright!
for(int scale = 0; scale < 93; scale++) {
LEDS.setBrightness(scale);
LEDS.show();
delay(wait_time);
}
// now let's fade down by scaling the brightness
for(int scale = 93; scale > 0; scale--) {
LEDS.setBrightness(scale);
LEDS.show();
delay(wait_time);
}
}

// this is the main loop where we call the other functions.
void loop() {
int waiting_time = 40; //time in ms for color scaling

setcolor(color_set); // we call our color-set routine

pulse(waiting_time); // now we make it fade in and out

color_set++; // OK - next color!
color_set = color_set % 3; // modulus, just so we always stay below 2 and our function works.
}
Loading

0 comments on commit e94281a

Please sign in to comment.