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.
Components
- Microcontroller board (Examples: PSoC, TI Tiva, or similar)
- Breadboard and jumper wires
- 10mm LEDs (3 red, 3 blue)
- 220-ohm resistors × 6
- 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 |
---|---|---|---|---|---|
Software 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.