Microbit Robotics Sensors & Circuits
Advanced
60 mins
345 points
What you need:
  • Microbit
  • LED Strip with crocodile clips

LED Strip Precision Game

Engage in a fun, interactive game using LED strips and your Microbit. Learn to program the LED strip, create variables, set up levels, and create functions. Develop your skills further by making the LED light move, hit targets, and handle game over scenarios. Finally, download your code, play the game and challenge others!

1 - Introduction

In this game one LED in the middle of your strip will light up yellow and another will light up blue and go back and forth along the length of the LED strip. The aim of the game is to press the A button when the moving blue LED passes over the yellow LED in the middle.

Each time you get it right the moving blue light will go a bit faster making the game more challenging.

If you press the A button when the moving blue light is not over the yellow LED then it's game over!

2 - Create a new Microbit project

To get started create a new Microbit project.

makecode.microbit.org

3 - Add the neopixel extension

To access the blocks we need to program the LED strip, you need to add the neopixel extension to your project.


4 - Setup the LED Strip

To be able to interact and program the LED strip we will need a variable that stores the strip.

Add the following code to your project. We set the value to be 30 as there are 30 LEDs on the strip.

5 - Create some variables

We will need 4 variables to store different values in this project. Create the following 4 new variables:

  1. 'target' this will be store the position of the yellow target LED light.
  2. 'position' this will store the current position of the moving blue LED light.
  3. 'delay' this will store the amount of time that the blue LED light delays until it moves to the next position.
  4. 'increment' this will store the amount of milliseconds that the blue LED light will move faster when you move to the next level.

Set the variables to the following values in the on start block:

  1. target = 15. This is the middle of the LED strip.
  2. position = 0. This is the first position on the LED strip.
  3. delay = 600. This is the amount of milliseconds we will delay for level 1.
  4. increment = -100. We will subtract 100 from the delay each time you finish a level.

Join our club 😃

To view the remaining 7 steps and access hundreds of other coding projects please login or create an account.

Copyright Notice
This lesson is copyright of Coding Ireland. Unauthorised use, copying or distribution is not allowed.
🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more