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.

PoliceLights 01

Required Components List

Component/DeviceDescriptionQuantity
R330ohm 220 Ω (red red brn gld / red red blk blk brn) × 6
LED Green 64 Red LED × 3
LED Green 64 Blue LED × 3
Button Small 64 Push Button (Switch) × 1

Circuit Diagram

  1. 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.
  2. Link every LED-resistor combo to a digital output terminal on the microcontroller.
  3. 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

DevicePort.Pin Signal TypeModuleDirectionDrive 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.

© 2024 Air Supply Information Center (Air Supply BBS)