Skip to main content

Posts

Showing posts with the label neopixel

Build a Disco cube:bit that reacts to music.

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

kitronik :Move mini buggy (Python control of LEDs)

In two previous posts I looked at control the :Move buggy using JavaScript Blocks or Python . In this post we are going to look at controlling the LEDs using Python (or more accurately micropython). Pin 0 controls the LEDs, they are based on 5   NeoPixel compatible,  RGB, addressable LEDs; so the Neopixel protocols (and library for Neopixels) can be used.  Code First five colours of the rainbow. The array lig  holds the RGB settings for the rainbow colours (more details on the RGB colours can be found at  Lorraine Underwood 's Halloween Cloud project ). In the code below, the five LEDs have a different colour allocated to them. from microbit import * import neopixel np = neopixel.NeoPixel(pin0, 5) lig=[[255,0,0],[255,127,0],[255,255,0],[0,255,0],[0,0,255],[75,0,136],[139,0,255]] while True:     np[0] = lig[0]     np[1] = lig[1]     np[2] = lig[2]     np[3] = lig[3] ...

4Tronix Bit:Bot - now there is a good idea.

When I first heard of this robot, my first thought was what a great idea; a robot with neopixels (I know I should be saying 'smart RGB LEDs' but neopixels is so much more snappier) controlled via a micro:bit. A good starting point for learning more about this robot, is the details on the 4Tronix site/blog , which includes build guidance and programming instructions for micropython and PXT. Though for the micropython code you might need to change pinX.digital_write() to pinX.write_digital()  where X is the pin number. My play code was to randomly select which neopixels to light up, I didn't include code to turn them off so multiple ones can be on. The robot is driven forwards, waits, backward, waits, turns to the right and then the left; and then repeats.  Code: from microbit import * import neopixel, random np = neopixel.NeoPixel(pin13, 12) def forward(n):     pin0.write_digital(1)     pin8.write_digital(0)  ...

Dancing pixels

In previous post I played with using the combination of the Proto-Pic Micro:pixel and Micro:Bit to react, using the accelerometer, to music through a computer speakers. 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 pixels colour. The latest version of this uses most of pixels. Coded in micropython using the Mu editor . from microbit import * import neopixel, random np = neopixel.NeoPixel(pin0, 32) while True:     for pxl in range (2,32, 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)       ...

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

micro:pixel board, micro:bit and micropython

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

Traffic lights - Microbit, GlowBugs and micropython

In a previous post, I got a GlowBug to work with a micro:bit ( http://robotsandphysicalcomputing.blogspot.co.uk/2016/08/microbit-and-glowbug.html ) . In this post, I will show a relatively simple traffic lights system produced by turning off and on the pixels via a micro:bit. Code from microbit import * import neopixel # Setup the Neopixel strip on pin0 with a length of 3 pixels np = neopixel.NeoPixel(pin0, 3) while True:     #red     np[0] = (255, 0, 0)     np[1] = (0,0, 0)     np[2] = (0,0,0)     np.show()     sleep(1000)     #red and orange     np[0] = (255, 0, 0)     np[1] = (255, 69, 0)     np[2] = (0,0,0)     np.show()     sleep(1000)     #green only     np[0] = (0, 0, 0)     np[1] = (0, 0, 0)     np[2] = (0,255,0)     np.show()     sleep(1000)   ...