Traffic lights - Microbit, GlowBugs and micropython

In a previous post, I got a GlowBug to work with a micro:bit (http://robotsandphysicalcomputing.blogspot.co.uk/2016/08/microbit-and-glowbug.html) . In this post, I will show a relatively simple traffic lights system produced by turning off and on the pixels via a micro:bit.




Code
from microbit import *
import neopixel

# Setup the Neopixel strip on pin0 with a length of 3 pixels
np = neopixel.NeoPixel(pin0, 3)

while True:
    #red
    np[0] = (255, 0, 0)
    np[1] = (0,0, 0)
    np[2] = (0,0,0)
    np.show()
    sleep(1000)
    #red and orange
    np[0] = (255, 0, 0)
    np[1] = (255, 69, 0)
    np[2] = (0,0,0)
    np.show()
    sleep(1000)
    #green only
    np[0] = (0, 0, 0)
    np[1] = (0, 0, 0)
    np[2] = (0,255,0)
    np.show()
    sleep(1000)
    #orange
    np[0] = (0, 0, 0)
    np[1] = (255, 69, 0)
    np[2] = (0,0,0)
    np.show()
    sleep(1000)





It is simple, timings and more lights can be added to make a more interesting system. If you have done something similar please use the comments to discuss or link to it.    

Thank you to @SCC_Lancaster for the loan of a micro:bit.


Related Posts
Microbit and GlowBugs
CodeBug and Glowbugs 



All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with.

Popular posts from this blog

Micro:bit, Servo control with Micropython or blocks

mbots - graphical programming and Arduino

4Tronix Bit:Bot Neuron Controlled Edge follower