Commit 99ce944d authored by Michael Nelson's avatar Michael Nelson

Implement running lights with 2 basic modes for now

parent 478754cd
......@@ -39,7 +39,7 @@
// Config
#define BLINK_RATE 250
#define RUNNING_LIGHT_BLINK_RATE 420
#define RUNNING_LIGHT_BLINK_RATE 920
#define HOLD_DOWN_TIME 350
// State
......@@ -91,7 +91,8 @@ void blink_frame(bool left, bool right, int tone_divisor = 2)
blinker_light_state = !blinker_light_state;
}
blink_speaker_frame(tone_divisor);
if (cycle_time == 1 && !blinker_light_state)
blink_speaker_frame(tone_divisor);
// Actual light
if (left)
......@@ -118,19 +119,20 @@ void running_light_frame(bool with_blink = false)
if (cycle_time > RUNNING_LIGHT_BLINK_RATE)
cycle_time = 0;
digitalWrite(PIN_OUT_BLINKER_L, !(cycle_time % 2 || cycle_time < 30) ? HIGH : LOW);
digitalWrite(PIN_OUT_BLINKER_R, !(cycle_time % 2 || cycle_time < 30) ? HIGH : LOW);
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_LEFT_BUTTON_LED, !(cycle_time % 2 || cycle_time < 30) ? HIGH : LOW);
digitalWrite(PIN_OUT_LEFT_BUTTON_LED, !(cycle_time % 9) || (with_blink && cycle_time < 70) ? HIGH : LOW);
cycle_time++;
}
void blink_speaker_frame(int divisor)
{
if (!blinker_light_state && cycle_time < 40) {
digitalWrite(PIN_OUT_SPEAKER, !(cycle_time % divisor) ? HIGH : LOW);
}
/* if (!blinker_light_state && cycle_time < 40) { */
/* digitalWrite(PIN_OUT_SPEAKER, !(cycle_time % divisor) ? HIGH : LOW); */
/* } */
tone(PIN_OUT_SPEAKER, 2000, 20);
}
// Each frame, this increments L/R/B hold time variables while the user is holding a button (or both) down.
......@@ -205,9 +207,12 @@ void set_up_mode()
// Cycle between running lights
else if (input_hold_left_hit)
{
bg_mode++;
if (bg_mode > BG_MODE_RUNNING_W_BLINK)
if (!bg_mode)
bg_mode = BG_MODE_RUNNING_LIGHTS;
else if (bg_mode >= BG_MODE_RUNNING_W_BLINK)
bg_mode = MODE_OFF;
else
bg_mode++;
fg_mode = MODE_OFF;
}
......@@ -257,8 +262,10 @@ void loop()
blink_frame(false, true);
else if (bg_mode == BG_MODE_HAZARDS)
blink_frame(true, true, 3);
/* else if (bg_mode == BG_MODE_RUNNING_LIGHTS) */
/* running_light_frame(); */
else if (bg_mode == BG_MODE_RUNNING_LIGHTS)
running_light_frame();
else if (bg_mode == BG_MODE_RUNNING_W_BLINK)
running_light_frame(true);
else
reset_all();
......
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