2016-04-11 04:11:38 +00:00
|
|
|
#include "SoftwareSerial.h"
|
|
|
|
#include "Adafruit_Pixie.h"
|
2023-03-18 21:13:41 +00:00
|
|
|
#include "McopySerial.h"
|
2016-04-11 04:11:38 +00:00
|
|
|
|
|
|
|
#define NUMPIXELS 1 // Number of Pixies in the strip
|
|
|
|
#define PIXIEPIN 6 // Pin number for SoftwareSerial output
|
|
|
|
|
|
|
|
SoftwareSerial pixieSerial(-1, PIXIEPIN);
|
|
|
|
Adafruit_Pixie light = Adafruit_Pixie(NUMPIXELS, &pixieSerial);
|
2023-03-22 00:38:45 +00:00
|
|
|
McopySerial mc;
|
2016-04-11 04:11:38 +00:00
|
|
|
|
2016-04-11 19:17:20 +00:00
|
|
|
String color = "000,000,000";
|
2016-04-11 04:11:38 +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-05-13 02:34:38 +00:00
|
|
|
unsigned long now; //to be compared to stored values every loop
|
|
|
|
unsigned long light_time;
|
2023-03-18 21:13:41 +00:00
|
|
|
volatile char cmd = 'z';
|
2016-05-13 02:34:38 +00:00
|
|
|
|
2016-04-11 04:11:38 +00:00
|
|
|
|
|
|
|
void setup () {
|
2023-03-22 00:38:45 +00:00
|
|
|
mc.begin(mc.LIGHT_IDENTIFIER);
|
2016-04-11 04:11:38 +00:00
|
|
|
pixieSerial.begin(115200); // Pixie REQUIRES this baud rate
|
2016-04-11 17:08:14 +00:00
|
|
|
light.setPixelColor(0, 0, 0, 0);
|
2016-05-25 19:58:49 +00:00
|
|
|
light.show();
|
2023-03-05 22:13:29 +00:00
|
|
|
r = 90;
|
|
|
|
g = 90;
|
|
|
|
b = 90;
|
2016-04-11 04:11:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop () {
|
2023-03-18 21:13:41 +00:00
|
|
|
now = millis();
|
|
|
|
cmd = mc.loop();
|
|
|
|
|
2023-03-22 00:38:45 +00:00
|
|
|
if (cmd == mc.LIGHT) {
|
2023-03-18 21:13:41 +00:00
|
|
|
color = mc.getString();
|
|
|
|
parseColorString();
|
2023-03-22 00:38:45 +00:00
|
|
|
mc.confirm(mc.LIGHT);
|
2016-05-13 02:34:38 +00:00
|
|
|
}
|
2016-04-11 04:11:38 +00:00
|
|
|
|
2023-03-18 21:13:41 +00:00
|
|
|
//send light signal to pixie every second
|
|
|
|
if (now - light_time >= 1000) {
|
|
|
|
light.setPixelColor(0, r, g, b);
|
|
|
|
light.show();
|
|
|
|
light_time = now;
|
2016-04-18 16:26:50 +00:00
|
|
|
}
|
2016-04-11 04:11:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-18 21:13:41 +00:00
|
|
|
void parseColorString () {
|
2016-04-11 19:17:20 +00:00
|
|
|
commaR = color.indexOf(','); //comma trailing R
|
|
|
|
commaG = color.indexOf(',', commaR + 1);
|
2016-04-11 04:11:38 +00:00
|
|
|
|
2016-04-11 19:17:20 +00:00
|
|
|
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 04:11:38 +00:00
|
|
|
|
2016-04-11 19:17:20 +00:00
|
|
|
r = strR.toInt();
|
|
|
|
g = strG.toInt();
|
|
|
|
b = strB.toInt();
|
2016-04-11 04:11:38 +00:00
|
|
|
|
2016-04-11 19:17:20 +00:00
|
|
|
light.setPixelColor(0, r, g, b);
|
2016-04-11 17:08:14 +00:00
|
|
|
}
|