BirdBlox LED Accelerometer
Use a tri-color LED to display the tablet’s current acceleration
Objective & Learning Goals
- Control Hummingbird outputs
- Use variables
- Read tablet sensors
- Attach a tri-color LED to port 1.
- If you have not already, attach the Hummingbird BLE Adapter module using the instructions here.
- Attach the external power cable.
- Open the BirdBlox app and connect to your Hummingbird.
- Tap Control to open the control category.
- The program should start when the green flag is tapped. Drag a when flag clicked block to the middle of the screen.
- Attach a repeat forever block below it. This will allow us to repeatedly change LED’s color to match the acceleration.
- 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.
- Tap Create Variable. Name the variable “red” and tap Okay. This variable will store the intensity of the red component of the LED.
- Create two more variables named “green” and “blue” using the same process.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- Change the variable to green and the Device Acceleration option to ‘Y.’
- Repeat this process for blue. The Device Acceleration option should be set to ‘Z.’
- 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!