Monday, 17 April 2017

Blog 3: What can "UCreate" with a Micro:bit and Neo-pixels(Neon Axe)

Last summer I created some resources to use with Micro:bit/s for CPC and over the next few months and I will try and share the best bits with the kind permission of CPC. 

This one uses Micropython and a neopixel again. The neopixel is from this kit:

The picture below shows how the Micro:bit is set up, It has 7 neo-pixel lights sequentially connected with clips. P.s. and Lots of tape to hold it all down!

Micro:bit code originally from: here 


"""
    neopixel_random.py

    Repeatedly displays random colours onto the LED strip.
    This example requires a strip of 7 Neopixels (WS2812) connected to pin0.

"""
from microbit import *
import neopixel
from random import randint

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

while True:
    #Iterate over each LED in the strip

    for pixel_id in range(0, len(np)):
        red = randint(0, 60)
        green = randint(0, 60)
        blue = randint(0, 60)

        # Assign the current LED a random red, green and blue value between 0 and 60
        np[pixel_id] = (red, green, blue)

        # Display the current pixel data on the Neopixel strip
        np.show()

        sleep(100)



Have a go :)

No comments:

Post a Comment