microbit playground and Edublocks: Controlling the pixels

Using the brilliant Edublocks specifically to microbit (https://microbit.edublocks.org/ ) I have been playing with a 4tronix Microbit playground








Set up use the Potentiometer attached to Pin1 to select which of eight neopixels is turned on.

The potentiometer output is turned into values between 0 (or 5 when I checked) and 1023; it is then divided, using the Floor operation (//, returns the integer part of a division), by 128 to give a number between 0 and 7. This number is used to selected which pixel attached to pin 0 lights up. Each pixel is set to white.

The text-based version of the python code is shown below
np = None
pot1 = None
pot2 = None

from microbit import *
import neopixel
np = neopixel.NeoPixel(pin0, 8)
while True:
  pot1 = pin1.read_analog()
  pot2=pot1//128
  np[pot2] = (32,32,32)
  np.show()
  sleep(50)
  np.clear()

via GIPHY

It is going to be interesting to explore both a bit more.







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