Print

BirdBlox LED Accelerometer

Use a tri-color LED to display the tablet’s current acceleration

Programming Language

BirdBlox

Subjects

Programming Tutorials

Grades

4-5, 6-8

Objective & Learning Goals

  • Control Hummingbird outputs
  • Use variables
  • Read tablet sensors

Hummingbird setup

  1. Attach a tri-color LED to port 1.
  2. If you have not already, attach the Hummingbird BLE Adapter module using the instructions here.
  3. Attach the external power cable.

Programming steps

  1. Open the BirdBlox app and connect to your Hummingbird.
  2. Tap Control to open the control category.
  3. The program should start when the green flag is tapped. Drag a when flag clicked block to the middle of the screen.
  4. Attach a repeat forever block below it. This will allow us to repeatedly change LED’s color to match the acceleration.
  5. The tablet can measure acceleration in the x, y, and z directions. We will make the red, green, and blue components of the tri-color LED reflect these three accelerations, respectively. To do this, we will need to temporarily store the three accelerations into memory slots, which are called variables. Open the Variables menu now.
  6. Tap Create Variable. Name the variable “red” and tap Okay. This variable will store the intensity of the red component of the LED.
  7. Create two more variables named “green” and “blue” using the same process.
  8. Now we will set the tri-color LED to use these variables. Later, we will set the values of these variables to equal the tablet’s acceleration. Go to the Hummingbird menu and place a Hummingbird TRI-LED block within the forever loop.
  9. Return to the Variables menu and drag the red, green, and blue variable blocks into the corresponding slots on the LED block. Leave the port set to port 1.
  10. Now let’s make the variables set themselves to the three different acceleration values. Add a set to block above the LED block. Tap the black arrow, and select red from the list.
  11. Locate the Device Acceleration block on the Tablet menu. Place this block in the set to block and select ‘X’ from the drop-down menu.
  12. Acceleration ranges roughly from -10 to 10 while LED values go from 0 to 100. To make the acceleration have a noticeable effect on the LED, we must multiply its value by 10. Move a multiplication block from the Operators menu to the middle of your screen.
  13. Move the Device Acceleration block into the first slot of the multiplication block. Then tap the second slot and type 10. Move the group of blocks back into the set to block.
  14. Run the program by tapping the green flag, and the tri-color LED should turn red when you place the tablet in the landscape orientation and tilt it. Tap the stop button when you are done. Now let’s work on the other colors.
  15. Copy the block configuration you have just assembled by long-pressing the set to block. Select Duplicate. Connect the new blocks right below the original configuration. Remove the extra HB TRI-LED block.
  16. Change the variable to green and the Device Acceleration option to ‘Y.’
  17. Repeat this process for blue. The Device Acceleration option should be set to ‘Z.’
  18. Run the program and you should be able to produce red, green, and blue by tilting your tablet. The LED will be red when the home button is on the left, green when the home button is on the top, and blue when the device is face down. See what colors you can make by tilting the tablet in different directions!