Merge light + projector sketches

light will remain on its own for experiments and test builds
This commit is contained in:
Matt 2016-04-18 21:25:18 -04:00
parent 64008bd10a
commit 7c9b56822e
1 changed files with 69 additions and 0 deletions

View File

@ -1,14 +1,47 @@
//Test lighting with NeoPixels instead of Pixies to prevent eye damage.
//LIGHT HEADERS
//#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);
//PROJECTOR HEADERS
String color = "000,000,000";
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;
boolean debug_state = false; boolean debug_state = false;
//const int proj_pin = 5; //relay 4 //const int proj_pin = 5; //relay 4
//const int proj_time = {{proj.time}}; //const int proj_time = {{proj.time}};
//const int proj_delay = {{proj.delay}}; //const int proj_delay = {{proj.delay}};
//LIGHT VARIABLES
//PROJECTOR VARIABLES
boolean proj_dir = true; boolean proj_dir = true;
const char cmd_light = 'l';
const char cmd_projector = 'p'; const char cmd_projector = 'p';
const char cmd_proj_forward = 'g'; const char cmd_proj_forward = 'g';
const char cmd_proj_backward = 'h'; const char cmd_proj_backward = 'h';
const char cmd_mcopy_identifier = 'm';
const char cmd_proj_identifier = 'j';
const char cmd_debug = 'd'; const char cmd_debug = 'd';
const char cmd_connect = 'i'; const char cmd_connect = 'i';
@ -19,6 +52,10 @@ void setup() {
Serial.begin(57600); Serial.begin(57600);
Serial.flush(); Serial.flush();
Serial.setTimeout(serialDelay); Serial.setTimeout(serialDelay);
//pixieSerial.begin(115200); // Pixie REQUIRES this baud rate
light.begin();
light.setPixelColor(0, 0, 0, 0);
light.show();
} }
void loop() { void loop() {
@ -37,12 +74,17 @@ void cmd (char val) {
debug(); debug();
} else if (val == cmd_connect) { } else if (val == cmd_connect) {
connect(); connect();
} else if (val == cmd_mcopy_identifier) {
identify();
} else if (val == cmd_projector) { } else if (val == cmd_projector) {
projector(); projector();
} else if (val == cmd_proj_forward) { } else if (val == cmd_proj_forward) {
proj_direction(true); proj_direction(true);
} else if (val == cmd_proj_backward) { } else if (val == cmd_proj_backward) {
proj_direction(false); proj_direction(false);
} else if (val == cmd_light) {
colorString();
Serial.println(cmd_light);//confirm light change
} }
} }
@ -57,6 +99,33 @@ void connect () {
log("connect()"); log("connect()");
} }
void identify () {
Serial.println(cmd_proj_identifier);
log("identify()");
}
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);
strB = color.substring(commaG + 1);
r = strR.toInt();
g = strG.toInt();
b = strB.toInt();
light.setPixelColor(0, r, g, b);
light.show();
}
void projector () { void projector () {
/* FROM INTVAL /* FROM INTVAL
* WILL USE OPTICAL ENDSTOP * WILL USE OPTICAL ENDSTOP