From 88e957b0c9926586fbb4fc4ed71502730d34f08a Mon Sep 17 00:00:00 2001 From: Lou Ferraro <112569056+FerralCoder@users.noreply.github.com> Date: Fri, 16 Feb 2024 10:23:27 -0600 Subject: [PATCH] Initial commit --- .gitignore | 0 .theia/settings.json | 7 +++++ PinAssignments.h | 19 +++++++++++++ RZR_Ignition_Delay_Indicator.ino | 46 ++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 .gitignore create mode 100644 .theia/settings.json create mode 100644 PinAssignments.h create mode 100644 RZR_Ignition_Delay_Indicator.ino diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/.theia/settings.json b/.theia/settings.json new file mode 100644 index 0000000..812bbb9 --- /dev/null +++ b/.theia/settings.json @@ -0,0 +1,7 @@ +{ +"editor.tabSize": 4, +"editor.renderWhitespace": "trailing", +"editor.insertSpaces": true, +"files.trimTrailingWhitespace": true, +"arduino.compile.warnings": "All" +} \ No newline at end of file diff --git a/PinAssignments.h b/PinAssignments.h new file mode 100644 index 0000000..7ca6df6 --- /dev/null +++ b/PinAssignments.h @@ -0,0 +1,19 @@ +#ifndef PIN_ASSIGNMENTS_H +#define PIN_ASSIGNMENTS_H + +// Each of these values corresponds to a pin on the Arduino Nano Every +enum PinAssignments : uint8_t { + // Ignition (digital input) + IgnitionPin = 8, + + // LED indicating ready to sense ignition (digital out) + ReadyLedPin = 4, + + // LED indicating ignition delay has completed. GO!! (digital out) + GoLedPin = 6, + + // Delay control (analog in) + DelayControlPin = A1 +}; + +#endif // PIN_ASSIGNMENTS_H \ No newline at end of file diff --git a/RZR_Ignition_Delay_Indicator.ino b/RZR_Ignition_Delay_Indicator.ino new file mode 100644 index 0000000..6ef92f4 --- /dev/null +++ b/RZR_Ignition_Delay_Indicator.ino @@ -0,0 +1,46 @@ +#include "PinAssignments.h" + +#define DELAY_CONTROL_MULTIPLIER 4 +#define MIN_IGNITION_DELAY_MS 1000 +#define STABILIZATOIN_DELAY_MS 500 + +void setup() +{ + // IN: Ignition wire + pinMode(IgnitionPin, INPUT); + // OUT: Ready LED + pinMode(ReadyLedPin, OUTPUT); + // OUT: Go LED + pinMode(GoLedPin, OUTPUT); + // IN: ADC from potentiometer to adjust delay (A0) + pinMode(DelayControlPin, INPUT); + analogReference(VDD); + + // Insert artificial delay to make sure all signals from the car are stable + delay(STABILIZATOIN_DELAY_MS); + + // Ready to sense ignition + digitalWrite(ReadyLedPin, HIGH); +} + +void loop() +{ + int DelayControlVal = 0; + long IgnitionDelay_ms = 0; + + // Read delay control value from potentiometer (range 0 to 1023) + DelayControlVal = analogRead(DelayControlPin); + + // Calculate delay + IgnitionDelay_ms = MIN_IGNITION_DELAY_MS + (DelayControlVal * DELAY_CONTROL_MULTIPLIER); + + if (digitalRead(IgnitionPin) == HIGH) + { + // Start delay + delay(IgnitionDelay_ms); + + // Light it up!! + digitalWrite(GoLedPin, HIGH); + digitalWrite(ReadyLedPin, LOW); + } +}