Correctly manage memory when reading from endstop

This commit is contained in:
Matt 2016-04-22 14:34:41 -04:00
parent 2697d9f721
commit 6fa80d63ee
1 changed files with 12 additions and 9 deletions

View File

@ -39,6 +39,7 @@ const int proj_fwd_pin = 5;
const int proj_bwd_pin = 6; const int proj_bwd_pin = 6;
volatile boolean proj_running = false; volatile boolean proj_running = false;
const int proj_endstop_pin = 4; const int proj_endstop_pin = 4;
volatile int proj_endstop_raw;
boolean proj_dir = true; boolean proj_dir = true;
//APP //APP
@ -82,10 +83,9 @@ void loop() {
} }
now = millis(); now = millis();
if (proj_running) { if (proj_running) {
if (proj_reading) { proj_reading();
proj_stop();
}
} }
delay(100);
//send light signal to pixie every second //send light signal to pixie every second
if (now - light_time >= 1000) { if (now - light_time >= 1000) {
light.setPixelColor(0, r, g, b); light.setPixelColor(0, r, g, b);
@ -167,18 +167,21 @@ void proj_start () {
//delay(1300); //TEMPORARY DELAY FOR TESTING TIMING //delay(1300); //TEMPORARY DELAY FOR TESTING TIMING
} }
boolean proj_reading () { void proj_reading () {
if (digitalRead(proj_endstop_pin)) { proj_endstop_raw = digitalRead(proj_endstop_pin);
return false; if (proj_endstop_raw == 0) {
} else { //do nothing
return true; } else if (proj_endstop_raw == 1) {
proj_stop();
} }
//delay(1); //needed? //delay(1); //needed?
} }
void proj_stop () { void proj_stop () {
digitalWrite(proj_bwd_pin, LOW); digitalWrite(proj_bwd_pin, LOW);
digitalWrite(proj_fwd_pin, LOW); digitalWrite(proj_fwd_pin, LOW);
proj_running = false;
Serial.println(cmd_projector); Serial.println(cmd_projector);
log("projector()"); log("projector()");