Skip to content

Instantly share code, notes, and snippets.

@CReimer
Created May 8, 2015 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CReimer/21239b5551cd6b8bd1fb to your computer and use it in GitHub Desktop.
Save CReimer/21239b5551cd6b8bd1fb to your computer and use it in GitHub Desktop.
Neobob with FastLED. (6 Byte prefix expected: 41 64 61 xx xx xx)
#include <FastLED.h>
//#define DEBUG
/*
* neobob_fastled
* Copyright (C) Christian Völlinger 2013
* Adapted for FastLED and simplified by Christopher Reimer [mail+neobob<AT>c-reimer.de]
*
* neobob is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* neobob is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define PIN 11
#define CLOCK 13
#define NOLEDS 50
CRGB leds[NOLEDS];
int rec;
int state = 1;
char buf[6];
const char prefix[] = {0x41, 0x64, 0x61};
#ifdef DEBUG
int failcounter = 0;
#endif
void setup()
{
FastLED.addLeds<WS2801, PIN, CLOCK, RGB>(leds, NOLEDS);
Serial.begin(500000);
// avoid using the loop function
for(;;) {
switch(state) {
case 1:
if(Serial.available() > 0) {
rec = Serial.read();
if(rec == prefix[0]) {
state = 2;
#ifdef DEBUG
Serial.print("Failed bytes: ");
Serial.println(failcounter, DEC);
failcounter = 0;
}
else {
failcounter++;
#endif
}
}
break;
case 2:
Serial.readBytes(buf, sizeof(prefix)*2 - 1); //There are 6 prefix bytes total. The first three is always the ascii code for 'ada'. The last three are configuration data. Our configuration is hardcoded. So skip them.
for(int p = 0; p < sizeof(prefix) - 1; p++) {
if(buf[p] == prefix[p+1]) {
state = 3;
}
else {
state = 1;
break;
}
}
break;
case 3:
Serial.readBytes( (char*)leds, NOLEDS * 3);
FastLED.show();
state = 1;
break;
}
}
}
void loop()
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment