2016-04-11 19:22:33 +00:00
|
|
|
//Test lighting with NeoPixels instead of Pixies to prevent eye damage.
|
|
|
|
|
|
|
|
//#include "SoftwareSerial.h"
|
|
|
|
//#include "Adafruit_Pixie.h"
|
|
|
|
|
|
|
|
#include <Adafruit_NeoPixel.h>
|
|
|
|
|
|
|
|
#define NUMPIXELS 1 // Number of Pixies in the strip
|
|
|
|
//#define PIXIEPIN 6 // Pin number for SoftwareSerial output
|
|
|
|
|
|
|
|
#define PIXELPIN 3 // Pin number for SoftwareSerial output
|
|
|
|
|
|
|
|
//SoftwareSerial pixieSerial(-1, PIXIEPIN);
|
|
|
|
//Adafruit_Pixie light = Adafruit_Pixie(NUMPIXELS, &pixieSerial);
|
|
|
|
|
|
|
|
Adafruit_NeoPixel light = Adafruit_NeoPixel(1, PIXELPIN, NEO_GRB + NEO_KHZ800);
|
|
|
|
|
2016-04-12 04:07:01 +00:00
|
|
|
String color = "000,000,000";
|
2016-04-11 19:22:33 +00:00
|
|
|
|
|
|
|
volatile int commaR = 0;
|
|
|
|
volatile int commaG = 0;
|
|
|
|
|
|
|
|
String strR = "000";
|
|
|
|
String strG = "000";
|
|
|
|
String strB = "000";
|
|
|
|
|
|
|
|
volatile int r = 0;
|
|
|
|
volatile int g = 0;
|
|
|
|
volatile int b = 0;
|
|
|
|
|
2016-04-18 16:26:50 +00:00
|
|
|
const char cmd_light = 'l';
|
|
|
|
|
2016-04-18 16:39:19 +00:00
|
|
|
const char cmd_debug = 'd';
|
|
|
|
const char cmd_connect = 'i';
|
2016-04-11 19:22:33 +00:00
|
|
|
volatile char cmd_char = 'z';
|
2016-04-12 03:05:05 +00:00
|
|
|
const int serialDelay = 5;
|
2016-04-11 19:22:33 +00:00
|
|
|
|
|
|
|
void setup () {
|
|
|
|
Serial.begin(57600);
|
|
|
|
Serial.flush();
|
2016-04-12 03:05:05 +00:00
|
|
|
Serial.setTimeout(serialDelay);
|
2016-04-11 19:22:33 +00:00
|
|
|
//pixieSerial.begin(115200); // Pixie REQUIRES this baud rate
|
|
|
|
light.begin();
|
2016-04-12 03:05:05 +00:00
|
|
|
light.setPixelColor(0, 0, 0, 0);
|
2016-04-11 19:22:33 +00:00
|
|
|
light.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop () {
|
|
|
|
if (Serial.available()) {
|
|
|
|
/* read the most recent byte */
|
|
|
|
cmd_char = (char)Serial.read();
|
|
|
|
}
|
|
|
|
if (cmd_char != 'z') {
|
|
|
|
cmd(cmd_char);
|
|
|
|
cmd_char = 'z';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2016-04-12 04:07:01 +00:00
|
|
|
//l - light - followed by String
|
2016-04-11 19:22:33 +00:00
|
|
|
//
|
|
|
|
void cmd (char val) {
|
2016-04-18 16:26:50 +00:00
|
|
|
if (val == cmd_connect) {
|
|
|
|
Serial.println(cmd_connect);//confirm connection
|
|
|
|
} else if (val == cmd_light) {
|
2016-04-11 19:22:33 +00:00
|
|
|
colorString();
|
2016-04-18 16:26:50 +00:00
|
|
|
Serial.println(cmd_light);//confirm light change
|
2016-04-11 19:22:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-12 03:05:05 +00:00
|
|
|
//takes 1004ms w/ string method
|
|
|
|
//takes 2ms(!!!!!) w/o readString() ugh
|
|
|
|
//WAIT!! Serial.setTimeout(1000) by default!
|
|
|
|
//500 - WORKS
|
|
|
|
//250 - WORKS
|
|
|
|
//100 - WORKS
|
|
|
|
//25? - WORKS
|
|
|
|
//5 - WORKS - STAY HERE FOR NOW
|
2016-04-11 19:22:33 +00:00
|
|
|
void colorString () {
|
|
|
|
while (Serial.available() == 0) {
|
|
|
|
//Wait for color string
|
|
|
|
}
|
|
|
|
color = Serial.readString();
|
|
|
|
//Serial.println(color);
|
|
|
|
|
|
|
|
commaR = color.indexOf(','); //comma trailing R
|
|
|
|
commaG = color.indexOf(',', commaR + 1);
|
|
|
|
|
|
|
|
strR = color.substring(0, commaR);
|
|
|
|
strG = color.substring(commaR + 1, commaG);
|
2016-04-11 19:59:48 +00:00
|
|
|
strB = color.substring(commaG + 1);
|
2016-04-11 19:22:33 +00:00
|
|
|
|
|
|
|
r = strR.toInt();
|
|
|
|
g = strG.toInt();
|
|
|
|
b = strB.toInt();
|
|
|
|
|
|
|
|
light.setPixelColor(0, r, g, b);
|
2016-04-12 03:05:05 +00:00
|
|
|
light.show();
|
2016-04-11 19:22:33 +00:00
|
|
|
}
|