LED State Machine
- Author
Braidan Duffy
Introduction
This class integrates the StateMachine
superclass and defines some NeoPixel-specific functions. The OlympianESC evaluation board uses a NeoPixel RGB LED for user feedback. This includes showing connection and error states, motor controls, and identification testing. The color and pattern of the LED depends on the system state as discussed in the next section.
LED Colors and Patterns
The NeoPixel RGB LED can be commanded to show a practically infinite range of colors in 255 brightness steps. For the system states defined in state_machine.h
, we can build a table for colors and patterns users can associate with each state:
System State |
Color(s) |
Pattern |
---|---|---|
IDLE_NO_CONNECTION |
Yellow |
Blinking |
IDLE_WITH_CONNECTION |
Yellow |
Solid |
PARTIAL_FORWARD |
Green |
Blinking |
PARTIAL_REVERSE |
Red |
Blinking |
FULL_FORWARD |
Green |
Solid |
FULL_REVERSE |
Red |
Solid |
DEVICE_IDENTIFY |
White, Magenta |
Blinking, alternating |
MOTOR_DISABLED |
Orange, Blue |
Blinking, alternating |
SENSOR_FAULT |
Orange, Magenta |
Blinking, alternating |
DRIVER_FAULT |
Orange, Cyan |
Blinking, alternating |
TRANSPORT_FAULT |
Orange, Yellow |
Blinking, alternating |
- Version
1.0
- Date
2024-03-05
- Copyright
Copyright (c) 2024
-
class LEDStateMachine : public StateMachine
Public Functions
-
inline LEDStateMachine(State ¤tStatePtr)
Construct a new LEDStateMachine object.
- Parameters:
currentStatePtr – Reference to the global
currentState
variable
-
void begin(void)
Initializes the NeoPixel LED and sets its brightness to
MAX_BRIGHTNESS
-
virtual void executeState()
Executes various LED state tasks based on the current system state. This should be executed in a continuous loop as it needs constant updating. Any LED functions executed within should be asynchronous (non-blocking). If applicable, they should also be thread safe.
Private Functions
-
void setLEDColor(uint32_t color)
Sets the NeoPixel LED to the color.
- Parameters:
color – Desired color to display on the LED.
-
void asyncBlink(uint32_t color, uint32_t interval = BLINK_PERIOD)
Asynchronously blinks the LED without blocking code execution (like when using
delay()
)- Parameters:
color – Desired color to display on the LED
interval – Interval the LED stays ON and OFF
-
void asyncAlternatingBlink(uint32_t firstColor, uint32_t secondColor, uint32_t interval = BLINK_PERIOD)
Asynchronously alternates between two different LED colors.
- Parameters:
firstColor – The first desired color to display on the LED.
secondColor – The second desired color to display on the LED.
interval – The interval each color will be displayed before switching.
-
inline LEDStateMachine(State ¤tStatePtr)