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) ...
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.