Button



Purpose

Today you will connect a button to control the lights.



Sandbox

Refresh yourself on what you did last time.

  1. Head to the microbit editor.
  2. Open a recent project you worked on.
  3. Download to a microbit.
  4. Tinker with the code. Change some values. Make it different.
  5. Download again.

Write in your sprint notes…

a couple important lines of code



Walkthrough

  1. Wire up a button according to this.
  2. Create a new project called Button Sample.
  3. Build this code that makes the LEDs change color every time you press the button. Button Sample
  4. Download and test it on your LED strip.

Take a picture…

of your code.

Note: Hang on to this picture. You’ll use this again soon in the assessment.



Exercises

Three Colors

Approaching

  1. Push the save button on your Walkthrough code.
  2. Change the name to Three Colors, and push the save button again. This gives you a new copy of your code.
  3. Modify the code to cycle through 3 different colors.

HINT: there’s a number you need to change in on pin P1 pressed.

Write in your sprint notes…

the file name of your updated code.



Three Effects

Distinguished

  1. Push the save button on your previous code.
  2. Change the name to Three Effects, and push the save button again. This gives you a new copy of your code.
  3. Modify the code to cycle through these 3 different effects:
    • moving rainbow
    • a moving dot (or multiple dots?)
    • solid color (that gets brighter and dimmer?)

HINT: look back at previous exercises you worked on.

Write in your sprint notes…

the file name of your updated code.