Snap! 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 Snap!".
4. Select level 4.
5. A sample project will load. After reading the note, delete both the note and the blocks by dragging them to the sidebar on the left of the screen.
Let's start by making the R, G, and B keys change the color of the Finch's beak.
6. We want the Finch's beak to turn red when the user presses the R key. Do to this, we will need a "key pressed" block. Select the "Control" category.
7. Drag a "When key pressed" block to the middle of the screen.
8. Change the block so it listens for the R key instead of the space bar.
9. To change the color of the Finch's beak, go to the "Looks" category and attach a "Finch LED" block to the "When key pressed" block.
10. Set the color to red by setting the number for red to 100 and making the other two numbers 0.
11. Press the R key and the beak should turn red.
12. Now let's make the G key cause the beak to turn green. Right-click (or control+click) the "When key pressed" block and select "Duplicate".
13. Place the stack of copied blocks in an empty space on your screen.
14. In this new set of blocks, change the key to G.
15. Set the color of the "Finch LED color" block to green by typing a 100 after the "G:" and setting the "R:" to 0.
16. Pressing the G key should now make the beak green.
17. 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.
18. Drag a "When key pressed" block to the middle of the screen.
19. Change the block so it listens for the up arrow key instead of the space bar.
20. Go to the "Motion" category and connect a "Move Finch" block to the "When key pressed" block.
21. Set the left and right motor power to 100.
22. Put the Finch on its tail so its wheels are off the ground. Then press the up arrow and the wheels should start to move. Click the "Stop Finch" block in the Motion category to stop the wheels.
23. 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.
24. 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.
25. Set the key to the up arrow.
26. 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 into the "wait until" block.
27. Finally, we need to tell the Finch to stop. Connect a "Stop Finch" block below the "wait until" block.
28. 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.
29. In this new set of blocks, change the "When key pressed" and "key pressed?" blocks so that they listen for the down arrow key.
30. To tell the Finch to go backwards, change the 100's in the "Move Finch" block to be -100.
31. Now it is time to make the Finch turn. Duplicate the blocks again and set them to the right arrow key.
32. Make the left wheel go forward (100) while the right wheel goes backwards (-100).
33. 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.
This file was created with the Birdbrain Robot Server. Use this utility to convert it to a form that can be used with the Chrome Finch connection app.