Showing posts with label @SCC_Lancaster. Show all posts
Showing posts with label @SCC_Lancaster. Show all posts

Wednesday, 3 August 2016

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.

Remote Data Logging with V1 Microbit

In an earlier post  https://robotsandphysicalcomputing.blogspot.com/2024/08/microbit-v1-datalogging.html  a single microbit was used to log ...