Commit 3aa12635 authored by Michael Nelson's avatar Michael Nelson

Finish bg mode implementation, and it's tested!

parent 99ce944d
......@@ -47,6 +47,7 @@ int fg_mode = MODE_OFF;
int bg_mode = MODE_OFF;
int blinker_light_state;
int last_fg_mode = MODE_OFF;
int last_bg_mode = MODE_OFF;
bool hold_waiting = false;
// Just-released variables
......@@ -116,17 +117,25 @@ void blink_frame(bool left, bool right, int tone_divisor = 2)
void running_light_frame(bool with_blink = false)
{
if (cycle_time > RUNNING_LIGHT_BLINK_RATE)
if (cycle_time >= RUNNING_LIGHT_BLINK_RATE)
cycle_time = 0;
digitalWrite(PIN_OUT_BLINKER_L, !(cycle_time % 9) || (with_blink && cycle_time < 70) ? HIGH : LOW);
digitalWrite(PIN_OUT_BLINKER_R, !(cycle_time % 9) || (with_blink && cycle_time < 70) ? HIGH : LOW);
digitalWrite(PIN_OUT_BLINKER_L, !(cycle_time % 20) || (with_blink && cycle_time < 70) ? HIGH : LOW);
digitalWrite(PIN_OUT_BLINKER_R, !(cycle_time % 20) || (with_blink && cycle_time < 70) ? HIGH : LOW);
digitalWrite(PIN_OUT_LEFT_BUTTON_LED, !(cycle_time % 9) || (with_blink && cycle_time < 70) ? HIGH : LOW);
digitalWrite(PIN_OUT_LEFT_BUTTON_LED, !(cycle_time % 20) || (with_blink && cycle_time < 70) ? HIGH : LOW);
cycle_time++;
}
void auxiliary_light_frame()
{
digitalWrite(PIN_OUT_BLINKER_L, HIGH);
digitalWrite(PIN_OUT_BLINKER_R, HIGH);
digitalWrite(PIN_OUT_RIGHT_BUTTON_LED, HIGH);
}
void blink_speaker_frame(int divisor)
{
/* if (!blinker_light_state && cycle_time < 40) { */
......@@ -217,18 +226,14 @@ void set_up_mode()
fg_mode = MODE_OFF;
}
else if (input_single_left_hit)
{
fg_mode = fg_mode == FG_MODE_BLINK_L ? MODE_OFF : FG_MODE_BLINK_L;
}
else if (input_hold_right_hit)
{
bg_mode = BG_MODE_AUXILARY_LIGHTS;
bg_mode = bg_mode == BG_MODE_AUXILARY_LIGHTS ? MODE_OFF : BG_MODE_AUXILARY_LIGHTS;
fg_mode = MODE_OFF;
}
else if (input_single_right_hit)
{
fg_mode = fg_mode == FG_MODE_BLINK_R ? MODE_OFF : FG_MODE_BLINK_R;
}
}
void reset_all()
......@@ -253,7 +258,8 @@ void loop()
set_up_mode();
// Reset all lights going directly from one direction to the next.
if (fg_mode != last_fg_mode && fg_mode != MODE_OFF)
if ((fg_mode != last_fg_mode && fg_mode != MODE_OFF) ||
(bg_mode != last_bg_mode && bg_mode != MODE_OFF))
reset_all();
if (fg_mode == FG_MODE_BLINK_L)
......@@ -266,8 +272,11 @@ void loop()
running_light_frame();
else if (bg_mode == BG_MODE_RUNNING_W_BLINK)
running_light_frame(true);
else if (bg_mode == BG_MODE_AUXILARY_LIGHTS)
auxiliary_light_frame();
else
reset_all();
last_fg_mode = fg_mode;
last_bg_mode = bg_mode;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment