Skip to content

Commit

Permalink
simple
Browse files Browse the repository at this point in the history
  • Loading branch information
Jade Meskill and Roy van de Water authored and Integrum User committed Dec 10, 2013
1 parent fd9c04e commit c368c67
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 91 deletions.
18 changes: 15 additions & 3 deletions spec/char_queue_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ class CharQueueTest : public CPPUNIT_NS::TestFixture {
CPPUNIT_TEST( test_size_after_a_push_and_a_pop );
CPPUNIT_TEST( test_size_after_two_pushes_and_a_pop );
CPPUNIT_TEST( test_size_after_a_pop );
CPPUNIT_TEST( test_double_pop_after_double_push );
CPPUNIT_TEST( test_tripple_pop_after_double_push );
CPPUNIT_TEST( test_clear_with_nothing );
CPPUNIT_TEST( test_clear_after_two_pushes );
CPPUNIT_TEST( test_this );
CPPUNIT_TEST_SUITE_END();

public:
Expand All @@ -37,7 +38,7 @@ class CharQueueTest : public CPPUNIT_NS::TestFixture {
}

void test_pop_with_nothing() {
CPPUNIT_ASSERT( !char_queue->pop() );
CPPUNIT_ASSERT_EQUAL( '\0', char_queue->pop() );
}

void test_pop_after_push() {
Expand Down Expand Up @@ -84,11 +85,12 @@ class CharQueueTest : public CPPUNIT_NS::TestFixture {
CPPUNIT_ASSERT_EQUAL( 0, char_queue->size() );
}

void test_double_pop_after_double_push() {
void test_tripple_pop_after_double_push() {
char_queue->push('f');
char_queue->push('b');
CPPUNIT_ASSERT_EQUAL( 'f', char_queue->pop() );
CPPUNIT_ASSERT_EQUAL( 'b', char_queue->pop() );
CPPUNIT_ASSERT_EQUAL( '\0', char_queue->pop() );
}

void test_clear_with_nothing() {
Expand All @@ -106,6 +108,16 @@ class CharQueueTest : public CPPUNIT_NS::TestFixture {
CPPUNIT_ASSERT_EQUAL( '\0', char_queue->pop() );
CPPUNIT_ASSERT_EQUAL( 0, char_queue->size() );
}

void test_this() {
char_queue->push('x');
char_queue->clear();
char_queue->push('f');

char mode = char_queue->pop();

CPPUNIT_ASSERT_EQUAL( 'f', mode );
}
};

CPPUNIT_TEST_SUITE_REGISTRATION( CharQueueTest );
Expand Down
152 changes: 64 additions & 88 deletions src/TestStatus.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <FastSPI_LED2.h>
#include <Animation.h>
#include "char_queue.h"

#define LED_COUNT 60
struct CRGB leds[LED_COUNT];
Expand All @@ -11,112 +10,107 @@ struct CRGB leds[LED_COUNT];
#define PIN_SIGNAL 13
#define PIN_INPUT 10

long last_time;
int pulse_interval;
CharQueue *read_buffer;
char mColor;

void setup()
{
last_time = millis();
pulse_interval = 0;
read_buffer = new CharQueue();
mColor = 't';

LEDS.addLeds<WS2811, PIN_SIGNAL, GRB>(leds, LED_COUNT); // this configures the BlinkyBoard - leave as is.
LEDS.showColor(CRGB(0, 0, 0));
LEDS.setBrightness(93); // Limit max current draw to 1A
LEDS.show();
test_sequence();
}


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!
// now let's fade down by scaling the brightness
for(int scale = 93; scale > 0; scale--) {
LEDS.setBrightness(scale);
LEDS.show();
delay(wait_time);
}
for(int scale = 0; scale < 93; scale++) {
LEDS.setBrightness(scale);
LEDS.show();
delay(wait_time);
}
bool is_color(char character) {
return (character == 'r' || character == 'g' || character == 'b' || character == 'y' || character == 'w');
}

int parse_pulse_interval(char mode) {
switch(mode) {
case 'f':
return 2;
case 'p':
return 5;
case 'x':
return -1;
default:
return 0;
void pulse() {
if (pulse_interval < 0) {
LEDS.setBrightness(93);
return;
}

int now = (millis() / pulse_interval) % 186;
LEDS.setBrightness(abs(93 - now));
LEDS.show();
}

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

static int pixelIndex;
int now = millis() / 50;
int r = now;
int g = now + 84;
int b = now + 84 + 84;

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[i].r = (r + i) % 254;
leds[i].g = (g + i) % 254;
leds[i].b = (b + i) % 254;
}
LEDS.show();
}

j = j + 1;
f = f + 1;
k = k + 2;
void set_color(char character) {
switch(character) {
case 'r':
case 'g':
case 'b':
case 'y':
case 'w':
case 't':
case 'x':
mColor = character;
return;
}
}

void solid_color(char color) {
switch(color) {
void color() {
switch(mColor) {
case 'r':
set_rgb(254, 0, 0);
break;
return;
case 'g':
set_rgb(0, 254, 0);
break;
return;
case 'b':
set_rgb(0, 0, 254);
break;
return;
case 'y':
set_rgb(254, 254, 0);
break;
return;
case 'w':
set_rgb(254, 254, 254);
break;
return;
case 't':
test_sequence();
return;
case 'x':
rainbow();
return;
}
}

void set_pulse_interval(char mode) {
switch(mode) {
case 'f':
pulse_interval = 2;
return;
case 'p':
pulse_interval = 5;
return;
case 's':
pulse_interval = 0;
return;
}
}

void set_rgb(int r, int g, int b) {
for (uint8_t i = 0; i < LED_COUNT; i++) {
leds[i] = CRGB(r,g,b);
}

LEDS.setBrightness(93);
LEDS.show();
}

Expand All @@ -128,31 +122,13 @@ void test_sequence() {
LEDS.show();
}

void read() {
void loop() {
while(Serial.available() > 0) {
char character = Serial.read();

if(character == 't') {
read_buffer->clear();
} else {
read_buffer->push(character);
}
set_color(character);
set_pulse_interval(character);
}
}

void loop() {
read();
if(read_buffer->size() >= 2) {
char mode = read_buffer->pop();
char color = read_buffer->pop();

solid_color(color);
pulse_interval = parse_pulse_interval(mode);
}

if(pulse_interval > 0) {
pulse(pulse_interval);
} else if (pulse_interval < 0) {
rainbow();
}
color();
pulse();
}
1 change: 1 addition & 0 deletions src/char_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class CharQueue {

void clear() {
while(this->pop()) {}
mTail = mHead;
}

char pop() {
Expand Down

0 comments on commit c368c67

Please sign in to comment.