Created framework for projector motor control

This commit is contained in:
Matt 2016-04-21 23:37:37 -04:00
parent eec3414364
commit be4002ed87
1 changed files with 55 additions and 29 deletions

View File

@ -29,14 +29,21 @@ volatile int r = 0;
volatile int g = 0; volatile int g = 0;
volatile int b = 0; volatile int b = 0;
unsigned long light_time;
//PROJECTOR VARIABLES //PROJECTOR VARIABLES
//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}};
const int proj_endstop_pin = 4;
const int proj_fwd_pin = 5;
const int proj_bwd_pin = 6;
volatile boolean proj_running = false;
const int proj_endstop_pin = 4;
boolean proj_dir = true; boolean proj_dir = true;
//APP
unsigned long now; //to be compared to stored values every loop
const char cmd_light = 'l'; 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';
@ -53,12 +60,15 @@ 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 //pixieSerial.begin(115200); // Pixie REQUIRES this baud rate
light.begin(); light.begin();
light.setPixelColor(0, 0, 0, 0); light.setPixelColor(0, 0, 0, 0);
light.show(); light.show();
pinMode(proj_endstop_pin, INPUT); pinMode(proj_endstop_pin, INPUT);
pinMode(proj_fwd_pin, OUTPUT);
pinMode(proj_bwd_pin, OUTPUT);
} }
void loop() { void loop() {
@ -70,12 +80,18 @@ void loop() {
cmd(cmd_char); cmd(cmd_char);
cmd_char = 'z'; cmd_char = 'z';
} }
if (digitalRead(proj_endstop_pin)) { now = millis();
Serial.println("blocked."); if (proj_running) {
} else { if (proj_reading) {
Serial.println("open."); proj_stop();
}
}
//send light signal to pixie every second
if (now - light_time >= 1000) {
light.setPixelColor(0, r, g, b);
light.show();
light_time = now;
} }
delay(500);
} }
void cmd (char val) { void cmd (char val) {
@ -86,14 +102,13 @@ void cmd (char val) {
} else if (val == cmd_mcopy_identifier) { } else if (val == cmd_mcopy_identifier) {
identify(); identify();
} else if (val == cmd_projector) { } else if (val == cmd_projector) {
projector(); proj_start();
} 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) { } else if (val == cmd_light) {
colorString(); light_set();
Serial.println(cmd_light);//confirm light change
} }
} }
@ -113,7 +128,7 @@ void identify () {
log("identify()"); log("identify()");
} }
void colorString () { void light_set () {
while (Serial.available() == 0) { while (Serial.available() == 0) {
//Wait for color string //Wait for color string
} }
@ -133,28 +148,38 @@ void colorString () {
light.setPixelColor(0, r, g, b); light.setPixelColor(0, r, g, b);
light.show(); light.show();
Serial.println(cmd_light);//confirm light change
log(color);
} }
void projector () { void proj_start () {
/* FROM INTVAL if (proj_dir) {
* WILL USE OPTICAL ENDSTOP digitalWrite(proj_fwd_pin, HIGH);
* Time_start(); digitalWrite(proj_bwd_pin, LOW);
cam_dir = dir;
if (cam_dir) {
analogWrite(PIN_MOTOR_FORWARD, fwd_speed);
analogWrite(PIN_MOTOR_BACKWARD, 0);
} else { } else {
analogWrite(PIN_MOTOR_BACKWARD, bwd_speed); digitalWrite(proj_bwd_pin, HIGH);
analogWrite(PIN_MOTOR_FORWARD, 0); digitalWrite(proj_fwd_pin, LOW);
} }
running = true; proj_running = true;
if (fwd_speed == 255) { delay(200); // Let flag pass out of endstop
delay(300);
//delay(1300); //TEMPORARY DELAY FOR TESTING TIMING
}
boolean proj_reading () {
if (digitalRead(proj_endstop_pin)) {
return false;
} else { } else {
delay(600); return true;
} }
micro_primed = false;*/ //delay(1); //needed?
delay(1300); //TEMPORARY DELAY FOR TESTING TIMING }
void proj_stop () {
digitalWrite(proj_bwd_pin, LOW);
digitalWrite(proj_fwd_pin, LOW);
Serial.println(cmd_projector); Serial.println(cmd_projector);
log("projector()"); log("projector()");
} }
@ -168,6 +193,7 @@ void proj_direction (boolean state) {
Serial.println(cmd_proj_backward); Serial.println(cmd_proj_backward);
log("proj_direction -> false"); log("proj_direction -> false");
} }
//delay(50); //delay after direction change to account for slippage of the belt
} }
void log (String msg) { void log (String msg) {