Remove delay() from Frame() and inter-frame delay

This gives the user the ability to stop sequences between exposures, or
during them.
This commit is contained in:
Matt McWilliams 2016-05-12 16:10:19 -04:00
parent 291ae33595
commit 59a696f6aa
1 changed files with 46 additions and 25 deletions

View File

@ -39,11 +39,14 @@ volatile int bwd_speed = 255;
volatile boolean sequence = false; volatile boolean sequence = false;
volatile boolean running = false; volatile boolean running = false;
volatile boolean cam_dir = true; volatile boolean cam_dir = true;
volatile boolean delaying = false;
volatile int micro_position = 0; volatile int micro_position = 0;
volatile boolean micro_primed = false; volatile boolean micro_primed = false;
unsigned long timer = 0; unsigned long timer = 0;
unsigned long frame_start = 0;
unsigned long delay_start = 0;
volatile int cam_count = 0; volatile int cam_count = 0;
volatile int cam_pos = 0; volatile int cam_pos = 0;
@ -61,7 +64,12 @@ void loop () {
Btn(2); Btn(2);
Btn(3); Btn(3);
if (running) { if (running) {
Read_micro(); timer = millis();
if (sequence && delaying) {
Watch_delay();
} else {
Read_micro();
}
} else { } else {
delay(LOOP_DELAY); delay(LOOP_DELAY);
} }
@ -74,8 +82,8 @@ void Pins_init () {
pinMode(PIN_INDICATOR, OUTPUT); pinMode(PIN_INDICATOR, OUTPUT);
} }
void Frame (boolean dir) { void Frame () {
cam_dir = dir; frame_start = millis();
if (cam_dir) { if (cam_dir) {
analogWrite(PIN_MOTOR_FORWARD, fwd_speed); analogWrite(PIN_MOTOR_FORWARD, fwd_speed);
analogWrite(PIN_MOTOR_BACKWARD, 0); analogWrite(PIN_MOTOR_BACKWARD, 0);
@ -84,24 +92,41 @@ void Frame (boolean dir) {
analogWrite(PIN_MOTOR_FORWARD, 0); analogWrite(PIN_MOTOR_FORWARD, 0);
} }
running = true; running = true;
if (fwd_speed == 255) {
delay(300);
} else {
delay(600);
}
micro_primed = false; micro_primed = false;
} }
void Read_micro () { boolean Read_delay () {
micro_position = digitalRead(PIN_MICRO); if (fwd_speed == 255) {
if (micro_position == LOW if (timer - frame_start >= 300) {
&& micro_primed == false) { return true;
micro_primed = true; }
} else if (micro_position == HIGH } else {
&& micro_primed == true) { if (timer - frame_start >= 600) {
Stop(); return true;
}
}
return false;
}
void Read_micro () {
if (Read_delay()) {
micro_position = digitalRead(PIN_MICRO);
if (micro_position == LOW
&& micro_primed == false) {
micro_primed = true;
} else if (micro_position == HIGH
&& micro_primed == true) {
Stop();
}
delay(2);//smooths out signal
}
}
void Watch_delay () {
if (timer - delay_start >= seq_delay) {
delaying = false;
Frame();
} }
delay(2);//smooths out signal
} }
void Stop () { void Stop () {
@ -120,8 +145,8 @@ void Stop () {
micro_primed = false; micro_primed = false;
if (sequence) { if (sequence) {
delay(seq_delay); delaying = true;
Trigger(); delay_start = millis();
} }
} }
@ -169,9 +194,9 @@ void button_end (int index, long buttontime) {
sequence = true; sequence = true;
Output(2, 250); Output(2, 250);
} }
Trigger(); Frame();
} else { } else {
Trigger(); Frame();
} }
} else if (index == 1) { //set direction } else if (index == 1) { //set direction
if (buttontime < 1000) { if (buttontime < 1000) {
@ -203,10 +228,6 @@ void button_end (int index, long buttontime) {
buttontime = 0; buttontime = 0;
} }
void Trigger () {
Frame(cam_dir);
}
void Output (int number, int len) { void Output (int number, int len) {
for (int i = 0; i < number; i++) { for (int i = 0; i < number; i++) {
Indicator(true); Indicator(true);