制造商零件编号 5625
ZIP HALO FOR THE BBC MICRO:BIT
Kitronik Ltd.
License: See Original Project
Courtesy of Pimoroni
Did you ever see in the movies when someone claps their hands twice and all the lights turn off?? I thought that was the coolest thing ever! Now, with the micro:bit, an enviro:bit, and some NeoPixel lights you can recreate that same effect!
Here's what you'll be making:
micro:bit #1 is going to be wearing the stylish enviro:bit. micro:bit #2 will be connected to one of the shiny ZIP Halo NeoPixel ring lights. When micro:bit #1 detects a clap, it will send a radio signal to micro:bit #2. micro:bit #2 will turn on/off the lights depending on the information it receives from micro:bit #1. Simples!
We’ll go through the code for both micro:bits. You’ll learn how to use the enviro:bit, the radio, and the NeoPixel package on the micro:bit.
We put the micro:bit with the ZIP Halo on inside an IKEA Sinnerlig glass lamp, after taking the original bulb and wiring out, and it makes a lovely mood light. We used battery packs to power both the ZIP Halo micro:bit and enviro:bit micro:bit, so the whole thing is wireless, but you could easily use wired power supplies for a more permanent solution.
Coding the micro:bit that is wearing the enviro:bit
This first part will set all of the code up on micro:bit #1 with the enviro:bit, sensing the claps and sending commands to micro:bit #2 with the radio to control the lights.
Setting up the package
For ease of use, we'll add the enviro:bit blocks package to your menu:
This will add the Enviro:Bit menu to your menu.
Setting up the radio
The micro:bit has a built-in radio function that lets you send commands from one micro:bit to another, and you can even send different commands to particular micro:bits by assigning them to different groups.
Let's set the radio up on micro:bit #1 to let it send commands to micro:bit #2.
Check for a double clap
Let’s check for a double clap first. If we hear a double clap, we'll send the number 2 to micro:bit #2. The double clap will turn the light off.
For a double clap, let’s send 2 to micro:bit #2 and also display 2 on the LED matrix on the micro:bit so that we can see better what's happening.
Check for a single clap
If it’s not a double clap, let’s check for a single clap and send the number 1 to micro:bit #2.
For a single clap, let’s send 1 to micro:bit #2 and also display 1 on the LED matrix on the micro:bit.
Extra code
If you find that the clap-sensing by the enviro:bit is too sensitive or not sensitive enough, then you can lower the sensitivity. Under on start, add the block Set clap sensitivity to 10 from the Enviro:Bit menu.
You can also add an if statement around the whole lot of code and only check for claps if the sound level is greater than 15. Your complete if statement would be if Get sound > 15.
Download the code from here, or from below, to a micro:bit and attach the enviro:bit to it.
Microsoft MakeCode | Terms of Use | Privacy | Download
Coding the light
This second part of the code is for micro:bit #2, and will receive radio commands from micro:bit #1 and then control the lights accordingly. We'll use the Kitronik ZIP Halo NeoPixel ring light connected to this micro:bit.
Select Project and New Project in the MakeCode editor to start a new project.
Setting up the NeoPixel package
Add the neopixel package to MakeCode.
Setting up the radio
Let's set the radio up to allow it to receive commands from micro:bit #1.
Setting up the lights
We need a variable that we'll set to control the lights. We'll give it the very clever name of… Lights
Making the lights react
Here's the plan:
Turning the lights on:
Turning the lights off:
Tada! Simples!
Extra code
It's a good idea to have an off switch, in case the double clap doesn’t work!
Download the code from here, or from below, to a micro:bit and attach the ZIP Halo to it. Kitronik have a nice guide on getting started with the ZIP halo on their site.
Microsoft Make Code | Terms of Use | Privacy | Download
Plug battery packs into both your micro:bits, remembering to plug the one powering the ZIP Halo into the connector on the Halo itself rather than the one on the micro:bit (it'll provide power to the micro:bit through the Halo).
Turn both battery packs on and turn the switch on the ZIP Halo to the on position also. Try clapping, and your light should turn on! Clap twice and it'll go off again. It can take a little experimentation to get the claps exactly right in terms of loudness and speed.
We used a couple of lumps of Blu Tack to attach the battery pack and the ZIP Halo to the base of the IKEA Sinnerlig lamp, and then popped the glass cover back on.