Skip to content

Commit

Permalink
Add a cop and an progress indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy van de Water authored and Roy van de Water committed Apr 8, 2014
1 parent ade3ad8 commit 38e707c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
1 change: 0 additions & 1 deletion spec/char_queue_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class CharQueueTest : public CPPUNIT_NS::TestFixture {
CPPUNIT_TEST( test_size_with_two_items );
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_tripple_pop_after_double_push );
CPPUNIT_TEST( test_clear_with_nothing );
CPPUNIT_TEST( test_clear_after_two_pushes );
Expand Down
54 changes: 54 additions & 0 deletions src/TestStatus.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ struct CRGB leds[LED_COUNT];
int mPulseInterval;
char mColor;
int mBrightness;
int mCommandStartTime;
char mLastColor;

void setup()
{
Expand Down Expand Up @@ -49,7 +51,55 @@ void color() {
case 'x':
rainbow();
return;
case 'c':
cop();
return;
case 'i':
indefinite_progress();
return;
}
}

void cop() {
int now = millis() / 100;
int phase = now % 5;

switch(phase) {
case 0:
case 1:
set_rgb(254, 0, 0);
return;
case 2:
case 3:
set_rgb(0, 0, 254);
return;
case 4:
set_rgb(254, 254, 254);
return;
}
}

void indefinite_progress() {
int time_elapsed = millis() - mCommandStartTime;

if(time_elapsed > 5000) {
return set_color(mLastColor);
}

int leds_to_show = time_elapsed / (5000 / LED_COUNT);

for (uint8_t i = 0; i < LED_COUNT; i++) {
if(i <= leds_to_show) {
leds[i].r = 254;
leds[i].g = 0;
leds[i].b = 254;
} else {
leds[i].r = 0;
leds[i].g = 0;
leds[i].b = 0;
}
}
LEDS.show();
}

bool is_color(char character) {
Expand Down Expand Up @@ -99,6 +149,10 @@ void set_color(char character) {
case 'w':
case 't':
case 'x':
case 'c':
case 'i':
mCommandStartTime = millis();
mLastColor = mColor;
mColor = character;
return;
}
Expand Down

0 comments on commit 38e707c

Please sign in to comment.