This repository has been archived by the owner on Oct 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Status lights #28
Draft
Benjamin-A
wants to merge
2
commits into
main
Choose a base branch
from
status_lights
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Status lights #28
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
60 changes: 32 additions & 28 deletions
60
fail_safe_firmware/FS_MCU_Arduino_Nano/FS_MCU_Arduino_Nano.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,43 @@ | ||
//DC input pins | ||
const byte pin_arm_input = 14; //Pin A0: RX Arm | ||
const byte pin_OtA_KS_input = 15; //Pin A1: RX Over the Air Kill Switch | ||
const byte pin_HW_KS_input = 16; //Pin A2: HW Kill Switch | ||
const byte pin_RX_timeout_input = 17; //Pin A3: RX timeout, if low then err | ||
#define pin_arm_input 14 //Pin A0: RX Arm | ||
#define pin_OtA_KS_input = 15 //Pin A1: RX Over the Air Kill Switch | ||
#define pin_HW_KS_input = 16 //Pin A2: HW Kill Switch | ||
#define pin_RX_timeout_input = 17 //Pin A3: RX timeout, if low then err | ||
|
||
const byte pin_RX_operation_mode_input = 19; //Pin A5: Operation Mode -- Software/Manual RX | ||
const byte pin_SW_KS_input = 20; //Pin A6: SW Kill Switch | ||
const byte pin_SW_operation_mode_input = 21; //Pin A7: Software Operation Mode -- Manual/Autonomous | ||
#define pin_RX_operation_mode_input = 19 //Pin A5: Operation Mode -- Software/Manual RX | ||
#define pin_SW_KS_input = 20 //Pin A6: SW Kill Switch | ||
#define pin_SW_operation_mode_input = 21 //Pin A7: Software Operation Mode -- Manual/Autonomous | ||
|
||
//DC output pins | ||
const byte pin_SW_fail_safe_status_output = 18; //Pin A4: SW Kill switch return | ||
|
||
const byte pin_main_output = 2; //Pin D2: MCU fail safe system MAIN OUTPUT | ||
const byte pin_LED_FS_locked_output = 3; //Pin D3: LED KS locked | ||
const byte pin_status_light_Y_output = 4; //Pin D4: Status light Y | ||
const byte pin_LED_RX_timeout_output = 5; //Pin D5: LED RX timeout | ||
const byte pin_LED_armed_output = 6; //Pin D6: LED Armed | ||
const byte pin_status_light_B_output = 7; //Pin D7: Status light B | ||
const byte pin_status_light_G_output = 8; //Pin D8: Status light G | ||
const byte pin_LED_SW_KS_status_output = 9; //Pin D9: LED SW KS | ||
const byte pin_LED_HW_KS_status_output = 10; //Pin D10: LED HW KS | ||
const byte pin_LED_OtA_KS_status_output = 11; //Pin D11: LED OtA KS | ||
const byte pin_status_light_R_output = 12; //Pin D12: Status light R | ||
#define pin_SW_fail_safe_status_output = 18 //Pin A4: SW Kill switch return | ||
#define pin_main_output = 2 //Pin D2: MCU fail safe system MAIN OUTPUT | ||
#define pin_LED_FS_locked_output = 3 //Pin D3: LED KS locked | ||
#define pin_LED_RX_timeout_output = 5 //Pin D5: LED RX timeout | ||
#define pin_LED_armed_output = 6 //Pin D6: LED Armed | ||
#define pin_LED_SW_KS_status_output = 9 //Pin D9: LED SW KS | ||
#define pin_LED_HW_KS_status_output = 10 //Pin D10: LED HW KS | ||
#define pin_LED_OtA_KS_status_output = 11 //Pin D11: LED OtA KS | ||
|
||
|
||
#define pin_LED_Y_output | ||
#define pin_LED_G_output | ||
#define pin_LED_R_output | ||
#define FULL_BRIGHTNESS 255 | ||
#define DIMMED_BRIGHTNESS 255 | ||
|
||
//The SW inputs may send 3.3 V or less and therefore need to be read by the ADC | ||
//The analog range 0V to 5V corresponds to the integer range 0 to 1023. | ||
const int analog_logic_high_cutoff = 670; | ||
#define analog_logic_high_cutoff = 670; | ||
|
||
//Declare functions | ||
void test_fail_safe_trigger(byte input_pin, byte LED_output_pin); | ||
void set_main_output(bool main_output_value); | ||
void status_lights(); | ||
void set_RGBY(bool R, bool G, bool B, bool Y); | ||
void test_fail_safe_trigger(byte input_pin, byte LED_output_pin); | ||
void set_main_output(bool main_output_value); | ||
void status_lights(); | ||
void set_LED_RGY(byte red, byte green, byte yellow); | ||
void default_pulsing_sequence(); | ||
void startup_sequence(); | ||
|
||
//Global Variables | ||
bool armed; | ||
bool fail_safe_locked; | ||
bool all_systems_go; | ||
bool armed; | ||
bool fail_safe_locked; | ||
bool all_systems_go; |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert changes, this breaks the Fail safe and does not improve functionality |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
status_light_MCU_Arduino_Nano/status_light_MCU_Arduino_Nano.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <Wire.h> | ||
|
||
|
||
//define pin numbers | ||
#define PIN_RED 11 | ||
#define PIN_YELLOW 10 | ||
#define PIN_GREEN 9 | ||
#define LED_PIN 13 // Onboard LED pin |
88 changes: 88 additions & 0 deletions
88
status_light_MCU_Arduino_Nano/status_light_MCU_Arduino_Nano.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#include "freyaStatusLightArduinoCode.h" | ||
|
||
//define variables | ||
int redValue = 26; // Default value | ||
int yellowValue = 26; // Default value | ||
int greenValue = 26; // Default value | ||
|
||
int header = 0; | ||
|
||
enum State { RUNNING, SIGNALLOSS }; | ||
State currentState = RUNNING; | ||
const int timeout = 1500; | ||
unsigned long currentTime; | ||
unsigned long lastMessageTime = millis(); | ||
|
||
void receiveEvent(int howMany) { | ||
lastMessageTime = millis(); | ||
// Blink the LED to indicate that data was received | ||
digitalWrite(LED_PIN, HIGH); // Turn on LED (indicate end of reception) | ||
|
||
if (howMany >= 4) { // Expecting 3 bytes | ||
header = Wire.read(); | ||
redValue = Wire.read(); | ||
yellowValue = Wire.read(); | ||
greenValue = Wire.read(); | ||
} | ||
// Return to RUNNING state if in SIGNALLOSS state | ||
if (currentState == SIGNALLOSS) { | ||
currentState = RUNNING; | ||
digitalWrite(LED_PIN, LOW); // Turn off LED in RUNNING state | ||
} | ||
} | ||
|
||
|
||
void setup() { | ||
// Initialize the PWM pins as outputs | ||
pinMode(PIN_RED, OUTPUT); | ||
pinMode(PIN_YELLOW, OUTPUT); | ||
pinMode(PIN_GREEN, OUTPUT); | ||
|
||
// Set the default PWM values | ||
analogWrite(PIN_RED, redValue); | ||
analogWrite(PIN_YELLOW, yellowValue); | ||
analogWrite(PIN_GREEN, greenValue); | ||
|
||
// Initialize the I2C bus as a slave device with address 8 | ||
Wire.begin(8); | ||
|
||
// Register the receive event | ||
Wire.onReceive(receiveEvent); | ||
|
||
// Store current time for signal loss detection | ||
currentTime = millis(); | ||
|
||
// Turn on the onboard LED to indicate that the code is running | ||
pinMode(LED_PIN, OUTPUT); | ||
digitalWrite(LED_PIN, LOW); | ||
} | ||
|
||
void loop() { | ||
|
||
switch (currentState) { | ||
case RUNNING: | ||
// Update the PWM signals on the pins | ||
analogWrite(PIN_RED, redValue); | ||
analogWrite(PIN_YELLOW, yellowValue); | ||
analogWrite(PIN_GREEN, greenValue); | ||
// Check for timeout | ||
currentTime = millis(); | ||
if (currentTime - lastMessageTime > timeout) { | ||
currentState = SIGNALLOSS; | ||
} | ||
break; | ||
|
||
case SIGNALLOSS: | ||
analogWrite(PIN_RED, 5); | ||
analogWrite(PIN_YELLOW, 5); | ||
analogWrite(PIN_GREEN, 5); | ||
delay(200); | ||
analogWrite(PIN_RED, 0); | ||
analogWrite(PIN_YELLOW, 0); | ||
analogWrite(PIN_GREEN, 0); | ||
delay(190); | ||
break; | ||
delay(10); | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert changes, this breaks the Fail safe and does not improve functionality