Skip to content

Arduino library for traffic lights

License

Notifications You must be signed in to change notification settings

nothrow/TrafficLight

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TrafficLight

Library for implementing european-style of traffic light. It incorporates state machine that correctly transitions from green to red and back.

Basic Use

Instatiation

#include <TrafficLight.h>

/// creates new object
TrafficLight traffic();

Setup

/// configures, which to which pins red/yellow/green lights/LEDs are connected
/// configures those pins as OUTPUT
traffic.attach(REDPIN, YELLOWPIN, GREENPIN);

/// low long does the transition take - how long does the "yellow" remains turned on
/// during transition
traffic.setInterval(1000);

Loop

/// should be called as often as possible - is nonblocking, and updates internal state
traffic.update();

/// triggers state transition to red light
traffic.red();

/// triggers state transition to green light
traffic.green();

/// triggers state transition to blinking yellow light
traffic.disable();

See examples/simple.cpp for full example.