{"id":16519656,"url":"https://github.com/propanedragon/picotrafficlight","last_synced_at":"2026-06-29T05:31:17.396Z","repository":{"id":95894206,"uuid":"555263108","full_name":"PropaneDragon/PicoTrafficLight","owner":"PropaneDragon","description":"A simple traffic light controller for Raspberry Pico","archived":false,"fork":false,"pushed_at":"2022-11-03T21:23:20.000Z","size":16120,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-02T22:29:16.937Z","etag":null,"topics":["cplusplus","cplusplus-17","raspberry","raspberry-pico","rp2040","traffic-light","traffic-light-control","traffic-light-controller"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PropaneDragon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":"colonelpanic","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2022-10-21T08:38:53.000Z","updated_at":"2022-11-02T22:01:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"f8084937-bc60-4609-8610-b45e0597a741","html_url":"https://github.com/PropaneDragon/PicoTrafficLight","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/PropaneDragon/PicoTrafficLight","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PropaneDragon%2FPicoTrafficLight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PropaneDragon%2FPicoTrafficLight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PropaneDragon%2FPicoTrafficLight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PropaneDragon%2FPicoTrafficLight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PropaneDragon","download_url":"https://codeload.github.com/PropaneDragon/PicoTrafficLight/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PropaneDragon%2FPicoTrafficLight/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34915001,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-29T02:00:05.398Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cplusplus","cplusplus-17","raspberry","raspberry-pico","rp2040","traffic-light","traffic-light-control","traffic-light-controller"],"created_at":"2024-10-11T16:47:44.075Z","updated_at":"2026-06-29T05:31:17.380Z","avatar_url":"https://github.com/PropaneDragon.png","language":"C++","funding_links":["https://ko-fi.com/colonelpanic"],"categories":[],"sub_categories":[],"readme":"# PicoTrafficLight\n\u003cimg src=\"/.github/images/individually-sequenced-crossing.gif\" width=\"400\" /\u003e\n\nAn easy to use traffic light controller for Raspberry Pico and possibly other RP2040 boards. Load this on to your board and attach to your projects to have a fully functional traffic light system that emulates systems from all over the world.\n\n## Features\n- Supports both common anode and common cathode light configurations on a light by light basis.\n- Contains common sequence configurations such as red-green or red-red+yellow-green with simple arguments.\n- Supports crossing lights as well as interrupts for button presses.\n- Supports manual advancing of lights from a custom trigger so you can set them up how you like them.\n- Contains a number of built systems to quickly get up and running.\n  - LightTestSystem - Runs through all LEDs in your traffic light to allow you to check which ones are operational.\n  - NAStopGiveWaySystem - Acts like flashing North American traffic lights where one direction flashes red and another flashes yellow.\n  - SequencedInterruptableSystem - Takes groups of traffic lights and sequences them one after another. Supports requests for crossing lights.\n  - SingleInterruptableCrossingSystem - Emulates traffic lights on a crossing where it will stay green until a crossing is requested and change to allow pedestrians to cross. Configurable to flash or change normally.\n- Configurable groups allows for sequencing large sets of lights.\n- Customisable sequences if the existing configurations aren't quite right for your use case.\n\n## Examples\n\u003cimg src=\"/.github/images/flashing-yellow-crossing.gif\" height=\"200\" /\u003e \u003cimg src=\"/.github/images/american-style.gif\" height=\"200\" /\u003e \u003cimg src=\"/.github/images/standard-crossing.gif\" height=\"200\" /\u003e\n\n## Use cases\n#### Scale models\nPurchase model traffic lights and plug directly into this system for use on scale models.\n#### Leaning and safety.\nEmulate real systems in a safe environment for kids to learn how to cross safely.\n#### Play\nBuild interactive toys around this system.\n\n## Guide\n### Creating a traffic light to control\nIn the below example we set up a new traffic light given pins for red, yellow, green, red crossing and green crossing lights. We then pass a `TrafficLight::LedType` enum which tells it whether it's a common anode or common cathode configuration:\n\n`std::make_shared\u003cTrafficLight\u003e(0u, 1u, 2u, 3u, 4u, TrafficLight::LedType::CommonAnode);`\n\nYou can also just pass red, yellow and green pins without crossing pins to set up for a traffic light system without a crossing, or you can pass only red and green crossing pins to set up for a stand-alone crossing light system.\nIf you want, you can manipulate this traffic light manually using the methods provided in the `TrafficLight` class, such as \n\n`void turnLightsOn(Light lights)`\n\nWhere `Light` is an enum of the lights to switch on. Multiple lights can be switched on at once by utilising the binary OR operator (| not ||). Example: `void turnLightsOn(TrafficLight::Light::Red | TrafficLight::Light::Yellow | TrafficLight::Light::RedCrossing)` which will turn on the red, yellow and red crossing lights all at once. See more available methods in [trafficlight.h](/trafficlight.h).\n\n### Creating traffic light groups\nIn addition to this, you can create groups of traffic lights which enable you to manipulate a set of traffic lights from one location. To create a group, first create your traffic lights as above, add them to a `std::vector\u003cstd::shared_ptr\u003cTrafficLight\u003e\u003e` then pass them into a group as shown below:\n\n```\nstd::vector\u003cstd::shared_ptr\u003cTrafficLight\u003e\u003e trafficLights = { trafficLight1, trafficLight2 };\nauto group = std::make_shared\u003cTrafficLightGroup\u003e(trafficLights);\n```\n\nYou can then manipulate a group in a similar way to a stand-alone `TrafficLight`, but any calls to methods on a group will affect all `TrafficLight`s within it at once. See [trafficlight_group.h](trafficlight_group.h) for available methods.\n\n### Controllers and sequences\nIf manually manipulating individual lights isn't your thing you can create or utilise `Controller`s and `Sequence`s to control groups of traffic lights automatically. A `Controller` is a simple system that allows you to simply run through a list of sequences and apply them to different traffic light groups. See the below example:\n\n```\nstd::vector\u003cstd::shared_ptr\u003cTrafficLight\u003e\u003e trafficLights = { trafficLight1, trafficLight2 };\n\nauto group = std::make_shared\u003cTrafficLightGroup\u003e(trafficLights);\nauto controller = std::make_shared\u003cController\u003e();\nauto sequence = std::make_shared\u003cTestSequence\u003e(std::chrono::milliseconds(300));\n\ncontroller-\u003eaddTrafficLightGroup(group, 0);\ncontroller-\u003eaddSequence(sequence, 0);\n\ncontroller-\u003erun();\n```\n\nIn the example above, a controller and sequence is created. The sequence is pre-made and available in [common_sequences](/common_sequences.h) and runs through all the available lights in a pattern to test they're working. You can utilise any sequence you like. The controller is then passed a traffic light group, which is given the ID of 0, and the sequence is added to manipulate the group ID of 0. When `run()` is called on the controller it runs through the sequences passed once then finishes. Let's expand it a bit:\n\n```\nstd::vector\u003cstd::shared_ptr\u003cTrafficLight\u003e\u003e allTrafficLights = { trafficLight1, trafficLight2 };\nstd::vector\u003cstd::shared_ptr\u003cTrafficLight\u003e\u003e trafficLightSet1 = { trafficLight1 };\nstd::vector\u003cstd::shared_ptr\u003cTrafficLight\u003e\u003e trafficLightSet2 = { trafficLight2 };\n\nauto allTrafficLightsGroup = std::make_shared\u003cTrafficLightGroup\u003e(trafficLights);\nauto trafficLightGroup1 = std::make_shared\u003cTrafficLightGroup\u003e(trafficLights);\nauto trafficLightGroup2 = std::make_shared\u003cTrafficLightGroup\u003e(trafficLights);\n\nauto controller = std::make_shared\u003cController\u003e();\nauto sequence = std::make_shared\u003cTestSequence\u003e(std::chrono::milliseconds(300));\n\ncontroller-\u003eaddTrafficLightGroup(allTrafficLightsGroup, 0);\ncontroller-\u003eaddTrafficLightGroup(trafficLightGroup1, 1);\ncontroller-\u003eaddTrafficLightGroup(trafficLightGroup2, 2);\n\ncontroller-\u003eaddSequence(sequence, 0);\ncontroller-\u003eaddSequence(sequence, 1);\ncontroller-\u003eaddSequence(sequence, 2);\n\ncontroller-\u003erun();\n```\n\nIn this example an additional two groups have been created which just consist of the first traffic light and second traffic light respectively. These groups are given the ID 1 and 2, and the same `TestSequence` sequence is added to those groups. When run, this will start the test sequence on group 0, which is both the traffic lights, so they will run through the same sequence together. Once tht is complete it will move onto the next sequence at ID 1, which is `trafficLight1` in the example. `trafficLight2` will be ignored and remain on the last active light, and `trafficLight1` will loop through the sequence. Finally, `trafficLight2` will loop through its sequence while `trafficLight1` remains static.\n\nYou don't have to only use a single controller, you can link controllers together and run them in seqeunce by simply calling `run()` on a sequence after a previous one has completed. For examples of this in use, see [Systems/sequenced_interruptable_system.cpp](/Systems/sequenced_interruptable_system.cpp).\n\n## How to build\n#### Easy method\n1. Fork this repository.\n1. Modify the main.cpp file to behave as you want. The current main.cpp file is set up to handle 2 traffic lights on GPIO pin 1, 2, 3, 4, 5, 6, 7, 8, 9 and 10 which will loop through different sequences indefinitely.\n1. Run the build action in GitHub.\n1. Download the produced trafficlight.uf2 file in the Binary artifact.\n1. Plug your Pico into your machine, copy the trafficlight.uf2 file onto it.\n1. Enjoy.\n\nIf programming isn't your thing, don't worry. I'm still working on a solution to build a set of standard traffic light setups and allowing you to create a custom system easily, but this may take some time.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpropanedragon%2Fpicotrafficlight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpropanedragon%2Fpicotrafficlight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpropanedragon%2Fpicotrafficlight/lists"}