Scratch Project 1: Simple Remote
Description: Make a simple program that uses the keyboard to control the Finch's movement and beak color.
Programming Concepts: Making key strokes trigger events, using blocks to control Finch motors and beak color
Approx. Time: 10 Minutes
1. Open the BirdBrain Robot Server.
2. Plug in your Finch and wait for the screen to say "Finch Connected".
3. Click "Open Scratch".
Let's start by making the R, G, and B keys change the color of the Finch's beak.
4. We want the Finch's beak to turn red when the user presses the R key. Do to this, we will need an event. Select the "Events" category.
5. Drag a "When key pressed" block to the middle of the screen.
6. Change the block so it listens for the R key instead of the space bar.
7. To change the color of the Finch's beak, go to the "More Blocks" category and attach a "Finch LED color" block to the "When key pressed" block.
8. Set the color to red by setting the number for red to 100 and making the other two numbers 0.
9. Press the R key and the beak should turn red.
10. Now let's make the G key cause the beak to turn green. Right-click (or shift+click) the "When key pressed" block and select "Duplicate".
11. Place the stack of copied blocks in an empty space on your screen.
12. In this new set of blocks, change the key to G.
13. Set the color of the "Finch LED color" block to green by typing a 100 after the "G:" and setting the "R:" to 0.
14. Pressing the G key should now make the beak green.
15. Duplicate the code again and make the B key turn the beak blue.
Now let's make the arrow keys control the Finch's movement.
16. Drag a "When key pressed" block to the middle of the screen.
17. Change the block so it listens for the up arrow key instead of the space bar.
18. Go to the "More Blocks" category and connect a "Move Finch" block to the "When key pressed" block.
19. Set the left and right motor power to 100.
20. The Finch should now start to move forward when you press the up arrow key. Now we need to make the Finch stop when the key is released. Click the "Control" category and attach a "wait until" block after the move block.
21. We will tell the Finch to wait until the up arrow is no longer pressed and then stop the motors. Click the "Sensing" category and place the "key pressed?" block inside the "wait until" block.
22. Set the key to the up arrow.
23. But we want to wait until the up arrow released, not pressed. To do this, grab a "not" block and drag it to an empty space on your screen. Move the "key pressed?" inside the "not" block and then move the not block in to the "wait until" block.
24. Finally, we need to tell the Finch to stop. Connect another "Move Finch" block below the "wait until" block, leaving the motor powers at 0.
25. The Finch should now move forward only when the up arrow is pressed. Now let's make the down key cause the Finch to move backwards. Duplicate the "when key pressed" block.
26. In this new set of blocks, change the "When key pressed" and "key pressed?" blocks so that they listen for the down arrow key.
27. To tell the Finch to go backwards, change the 100's in the "Move Finch" block to be -100.
28. Now it is time to make the Finch turn. Duplicate the blocks again and set them to the right arrow key.
29. Make the left wheel go forward (100) while the right wheel goes backwards (-100).
30. Finally, duplicate the code one last time and make the Finch turn left when the left arrow key is pressed. Use -100 for the left wheel and 100 for the right wheel.
The program is complete! You should now be able to control the Finch with your keyboard.