Tyeth
Published © GPL3+

Raspberry Pi Zero W - Automation pHAT - Traffic Light Tower

Just a quick play through with the Pimoroni 12V Traffic Light Tower, combined with the recent Automation pHAT, hooked up to a Raspberry Pi.

EasyWork in progress2 hours1,115

Things used in this project

Hardware components

Raspberry Pi Zero Wireless
Raspberry Pi Zero Wireless
×1
3 Colour 12V Traffic Light Tower
×1
Pimoroni Automation pHAT
×1

Software apps and online services

SSH Client
Can be skipped if you access the pi directly with a screen and keyboard etc.
*Optional* Adapters and Cables
*Optional* Adapters and Cables to connect screen and keyboard to Pi, OR USE SSH

Hand tools and fabrication machines

Thing for making holes.
Soldering iron (generic)
Soldering iron (generic)
Electrical Insulating Tape (PVC tape)

Story

Read more

Code

demo code to test automation outputs 1-3 in an endless loop

Python
Pimoroni Automation pHAT demo code
#!/usr/bin/env python

import automationhat
import time
import os
import sys

counter = -1
lightPattern = [
    [1,0,0],
    [0,1,0],
    [0,0,1],
    [0,1,1],
    [0,1,0],
    [1,1,0],
    [1,0,0],
    [1,1,0],
    [0,1,0],
    [0,1,1],
    [0,0,1],
    [0,0,0],
    [1,0,1],
    [0,1,0],
    [0,0,0],
]

def increment():
    global counter
    counter+=1
    if counter==len(lightPattern):
        counter = 0

def doCurrentCycle():
    currentCycle = lightPattern[counter]
    print currentCycle
    if (currentCycle[0]==1) :
        automationhat.output.one.on()
    else:
        automationhat.output.one.off()

    if (currentCycle[1] == 1):
        automationhat.output.two.on()
    else:
        automationhat.output.two.off()

    if (currentCycle[2] == 1):
        automationhat.output.three.on()
    else:
        automationhat.output.three.off()

    time.sleep(2)



while True:
    increment()
    doCurrentCycle()

Credits

Tyeth

Tyeth

3 projects • 3 followers
Love solving problems
Contact

Comments