Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
LightLine Kit Arduino Firmware v1
#include <SoftwareSerial.h>
#include <Adafruit_NeoPixel.h>
//SoftwareSerial softSerial(8, 9); // RX, TX
#define BUFFER_SIZE 256
char input[BUFFER_SIZE];
int currPos = 0;
bool bReading = false;
bool bParsingColors = false;
bool bParsingColorsFlagFound = false;
uint16_t colorNum = 0;
//#define Z1 220.0
//#define Z2 698.0
#define NEO_PIN 6
//#define ESP8266_CHPD 6
//#define BUTTON 3
int buttonState = 0;
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed
Adafruit_NeoPixel strip = Adafruit_NeoPixel(30, NEO_PIN, NEO_GRB + NEO_KHZ800);
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pix @el. Avoid connecting
// on a live circuit...if you must, connect GND first.
void setup() {
Serial.begin(57600);
delay(1000);
strip.begin();
fillColor( strip.Color(50,50,50) );
delay(1500);
Serial.print("AT+CIPMUX=1\r\n");
delay(1000);
Serial.print("AT+CIPSERVER=1,40002\r\n");
delay(1000);
Serial.print("AT+CIPSTO=120\r\n");
fillColor( strip.Color(100,100,100) );
delay(3000);
fillColor( strip.Color(255,255,255) );
delay(100);
printIP();
}
void printIP() {
blnk(100);
Serial.print("AT+CIFSR\r\n");
}
void loop() {
while ( Serial.available() ) {
char inByte = Serial.read();
//softSerial.write(inByte);
if (bReading) {
if (inByte == '\r') {
if(bParsingColors) {
parseColor();
bParsingColors = false;
bParsingColorsFlagFound = false;
strip.show();
}
bReading = false;
}
else if (inByte != '\n') {
if(currPos == 0 && inByte == '+') {
bParsingColors = true;
}
else {
if(bParsingColors) {
if(!bParsingColorsFlagFound) {
if(inByte == ':') {
bParsingColorsFlagFound = true;
colorNum = 0;
currPos = 0;
continue;
}
}
else {
if(inByte=='-') {
parseColor();
currPos = 0;
colorNum++;
continue;
}
}
}
input[currPos] = inByte;
currPos++;
}
if(currPos >= BUFFER_SIZE-1) {
fillColor( strip.Color(125, 0, 0) );
currPos = 0;
colorNum = 0;
bParsingColors = false;
bParsingColorsFlagFound = false;
bReading = false;
}
}
}
else {
if (inByte == '\n') {
bReading = true;
currPos = 0;
}
}
}
delay(1);
}
long readVcc() {
long result;
// Read 1.1V reference against AVcc
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Convert
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result = 1126400L / result; // Back-calculate AVcc in mV
return result;
}
void parseColor() {
int r, g, b;
input[currPos] = '\0';
if (strlen(input) == 6) {
char cr[3] = {
'\0' };
strncpy(cr, input, 2);
char cg[3] = {
'\0' };
strncpy(cg, (input+2), 2);
char cb[3] = {
'\0' };
strncpy(cb, input+4, 2);
r = strtol( cr, NULL, 16 );
g = strtol( cg, NULL, 16 );
b = strtol( cb, NULL, 16 );
}
else {
r = g = b = strtol( input, NULL, 16 );
}
strip.setPixelColor(colorNum, strip.Color(r, g, b));
}
// LEDS
void blnk(int duration) {
fillColor( strip.Color(50, 50, 50) );
delay(duration);
fillColor( strip.Color(0, 0, 0) );
delay(duration);
}
void fillColor(uint32_t c) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
}
strip.show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment