An Arduino library for controlling traffic lights with red, yellow, and green LED pins.
This is an Arduino library for controlling traffic lights using red, yellow, and green LED pins. The library provides simple functions to manage traffic light behavior, such as cycling through the lights with customizable timing.
- Simple and easy to use.
- Control red, yellow, and green LEDs.
- Functions to cycle through lights with delays.
- Download the library from GitHub as a ZIP file.
- In the Arduino IDE, go to Sketch > Include Library > Add .ZIP Library...
- Select the downloaded ZIP file to install the library.
- Include the library in your sketch:
#include <TrafficLights.h>
- Define the pin numbers for the LEDs and create a
TrafficLights
object:TrafficLights trafficLight(redPin, yellowPin, greenPin);
- In the
setup()
function, initialize the pins:trafficLight.begin();
- In the
loop()
function, cycle through the traffic lights:trafficLight.cycleLights(3000); // 3 seconds delay between each light
Here is an example of how to use the TrafficLights
library in a sketch:
#include <TrafficLights.h>
const int redPin = 13;
const int yellowPin = 12;
const int greenPin = 11;
TrafficLights trafficLight(redPin, yellowPin, greenPin);
void setup() {
trafficLight.begin();
}
void loop() {
trafficLight.cycleLights(3000);
}