A new (or to me at least) addition to devices you can attach a Micro:Bit to, is the Proto-Pic micro:pixel 4x8 NeoPixel board; essentially a board with 4 x8 grid of NeoPixels that you plug the Micro:Bit into. Following the advice of the website the values of RGB are all set to 32 or below to avoid pulling too much power. Pin0 is used to write to. You will need to use the Mu editor for this.
Two tests were tried
Example 1: To get the pixels to appear to light up from the last to the first one.
from microbit import *
import neopixel
np = neopixel.NeoPixel(pin0, 32)
while True:
for x in range(0, 32):
for y in range(0, (32-x)):
np[y] = (y, 32-y, 1)
if (y>0):
np[y-1]=(0,0,0)
np.show()
sleep(30)
Example 2: To randomly select a pixel and its colour.
from microbit import *
import neopixel, random
np = neopixel.NeoPixel(pin0, 32)
while True:
pxl=random.randint(0,31)
rd=random.randint(1,32)
gr=random.randint(1,32)
bl=random.randint(1,32)
np[pxl] = (rd, gr, bl)
np.show()
sleep(500)
np[pxl] = (0, 0, 0)
This is a good, fun board to play with; relatively easy to use.
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. Twitter @scottturneruon
No comments:
Post a Comment