The LAMP:bit - Part 2

The LAMP:bit - Part 2

Learn how to control your LAMP:bit without even touching it!

Now that you've learnt the basics from my last blog, we can get into some more technical stuff. This extension isreally cool because it works just like the street lights or automatic car headlights do. When the sun goes down and it gets darker, the lights turn on, and when it’s light outside, the lights stay off. Keep reading to find out how you can make your LAMP:bit do the same!

For this, you’ll need the following: 

A really cool thing you can do with theLAMP:bit is to make the light turn on or off depending on how much light there is on the phototransistor. When the room is dark, the lamp can turn on, and then turn off when the room is light. To do this, you need to start with a ‘forever’ code block, and add the "logic" block so it look like this:

Then, drag a comparison code block from logic onto the area that says “true”. On the left side of the comparison code block, add the ‘read light level’ from the LAMP:bit code blocks. On the right, change the number to 512.

We want the lamp to turn on when the room is dark and turn off when the room is light. To do this, add a ‘turn lamp light’ block in the first part and set it to ‘on’, then add another ‘turn lamp light’ block to the bottom part and set it to ‘off’.

Now you're ready to code your micro:bit! Download it onto your device, then upload it onto your micro:bit. You can test this code by moving your hand over the top of the lamp. When your hand is over it, the light should turn on, and turn off when you move your hand again. 

*Expert Tip*
This might not work if you're in a room with the lights turned on. Try taking it outside into the natural light and testing it out there!


Leave a comment

Comments will be approved before showing up.

Join our VIP Club