In a previous post Micro:bit and Cube:bit 'says' Hello I introduced the start of me playing with the 4tronix Cube:bit. One of the things I want to try is get the cube to react to music, based around the accelerometers in a micro:bit picking up vibrations. Luckily, in an earlier post, I had done something similar for the Proto-Pic Micro:pixel (see Dancing Pixels for more details).
Essentially the idea is the vibrations from the music shake the micro:bit enough to give measurable changes in three axis, and these values are used to change the pixel's colour - in fact five pixels at a time.
The code shown below is all that was needed:
from microbit import *
import neopixel, random
np = neopixel.NeoPixel(pin0, 125)
while True:
for pxl in range (2,125, 5):
rd=int(abs(accelerometer.get_x())/20)
gr=int(abs(accelerometer.get_y())/20)
bl=int(abs(accelerometer.get_z())/20)
np[pxl] = (rd, gr, 0)
np[pxl-1] = (rd, gr, 0)
np[pxl+1] = (0, gr, rd)
np[pxl-2] = (rd, 0, 0)
np[pxl+2] = (0, gr,0)
np.show()
Here it is in action:
The music used in the video is
Please feel free to improve on this.
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
Robots and getting computers to work with the physical world is fun; this blog looks at my own personal experimenting and building in this area.
Showing posts with label disco. Show all posts
Showing posts with label disco. Show all posts
Saturday, 1 September 2018
Saturday, 22 October 2016
Disco micro:pixel
In a previous post Proto-Pic board, Microbit and Micropython I played with the Proto-Pic micro:pixel 4x8 NeoPixel board.
This post is just a short description of a quick play with making it flashing blocks of different colours across the board. The routine produces five random numbers (three to define the colours, one for which pixel is selected and the last for the delay each iteration). The idea of being - a pixel is selected, but so are the ones either side of it, each one has a different combination of the colour values, but only two of the pixels are turned off after the delay.
from microbit import *
import neopixel, random
# Setup the Neopixel strip on pin0 with a length of 2 pixels
np = neopixel.NeoPixel(pin0, 32)
while True:
pxl=random.randint(1,30)
rd=random.randint(1,32)
gr=random.randint(1,32)
bl=random.randint(1,32)
t1=random.randint(10,100)
np[pxl] = (rd, gr, bl)
np[pxl-1] = (gr, bl, rd)
np[pxl+1] = (bl, rd, gr)
np.show()
sleep(t1)
np[pxl] = (0, 0, 0)
np[pxl+1] = (0, 0, 0)
The video below shows the routine in action. There is no connection between the pixels and the music on the video - but making the connection between music and the pixels would be an interesting project.
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
Subscribe to:
Posts (Atom)
Who wants to produce AI produced cartoon strips
Question: How easy is it produce a comic/cartoon using genetative AI? Let's start with using ChatGPT4o to produce cartoons. The idea wa...