Project 002: Police LED Light Bar Simulation
Objective
- Develop and code an electronic setup using LEDs and a microcontroller to imitate the police LED light bar.
Required Components List
Component/Device | Description | Quantity |
---|---|---|
220 Ω (red red brn gld / red red blk blk brn) | × 6 | |
Red LED | × 3 | |
Blue LED | × 3 | |
Push Button (Switch) | × 1 |
Circuit Diagram
- Position the six LEDs on your breadboard, and pair each one with a 220-ohm resistor. These resistors ensure safe current levels for the LEDs, preventing potential damage.
- Link every LED-resistor combo to a digital output terminal on the microcontroller.
- Attach the push button switch to a digital input on the microcontroller, configuring the pins to function in input mode with an accompanying pull-up resistor.
Pin configurations
Device | Port.Pin | Signal Type | Module | Direction | Drive Mode |
---|---|---|---|---|---|
Implementation
You are tasked with crafting a minimum of three distinctive police LED light sequences. Consider utilizing a struct to structure the LED sequence as demonstrated::
typedef struct LEDPAT{
uint8_t leds;
uint8_t duration;
} LEDPAT;
Structure three pattern arrays as shown:
LEDPAT Pattern1[] = {
{ , }, // First item
...
};
LEDPAT Pattern2[] = {
{ , }, // First item
...
};
LEDPAT Pattern3[] = {
{ , }, // First item
...
};
Within the "main()" function, iterate through your pattern arrays. Illuminate the LEDs as directed by the "leds" parameter in the pattern, and introduce a pause (in milliseconds) as dictated by the "duration" parameter. When the switch (SW1) is activated, shift to the subsequent pattern. Employ software edge-detection techniques to ascertain SW1's state.
Note: Feel free to modify LED sequences and their respective durations to suit your preferences.