Year 3 - Lesson 2
(Key Moves)
Learning Intention
- I can program program a robot to move when keys are pressed.
Introduction
How do you control players when playing computer games? One way is using a computer keyboard with different keys triggering the computer game sprite to carry out different movements such as jumping. We are going to write programs to make Ohbot carry out different sequences of movements when different keys are pressed.
How do you control players when playing computer games? One way is using a computer keyboard with different keys triggering the computer game sprite to carry out different movements such as jumping. We are going to write programs to make Ohbot carry out different sequences of movements when different keys are pressed.
Teacher Input 1
Let’s make Ohbot nod once whenever the N key is pressed. First we will start with an event instruction. In the last lesson we used the When green flag clicked event block to start our sequence. This time we are going to use When___ Key Pressed. Use the drop down menu to select N as the trigger key.
The scripts will be similar to those created in the previous lesson. Use 10 and 0 for maximum movements in either direction and 5 tol bring Ohbot back to the middle point. Work through the N for nod instructions with the children. Ask the children to write the code for S for shake by themselves using the N for nod code as a skeleton. Select Save As from the File menu and save the program with the name ‘ keyboard N and S’. Children to now work through tasks on slides.
Let’s make Ohbot nod once whenever the N key is pressed. First we will start with an event instruction. In the last lesson we used the When green flag clicked event block to start our sequence. This time we are going to use When___ Key Pressed. Use the drop down menu to select N as the trigger key.
The scripts will be similar to those created in the previous lesson. Use 10 and 0 for maximum movements in either direction and 5 tol bring Ohbot back to the middle point. Work through the N for nod instructions with the children. Ask the children to write the code for S for shake by themselves using the N for nod code as a skeleton. Select Save As from the File menu and save the program with the name ‘ keyboard N and S’. Children to now work through tasks on slides.
Activity
1. Write a program to make Ohbot’s eyes look up and down when U is pressed and look left and right when L is pressed.
Extension
Can you write the code to control Ohbot’s lips using the keyboard? T for top lip and B for bottom lip.
1. Write a program to make Ohbot’s eyes look up and down when U is pressed and look left and right when L is pressed.
Extension
Can you write the code to control Ohbot’s lips using the keyboard? T for top lip and B for bottom lip.
Plenary
When we use the keyboard to control Ohbot, Ohbot’s head will continue to move up and down as long as the N (for nod) key is being pressed. Consequently, if you press N again and again Ohbot will nod again and again. However, in programming this is not the most efficient way to get a robot to perform an instruction multiple times. Have a look around in the Ohbot instructions to see if you can find a more efficient way to perform movements again and again?
We need to use the repeat instruction from the Control palette. Next week we learn to write code using repeat.
When we use the keyboard to control Ohbot, Ohbot’s head will continue to move up and down as long as the N (for nod) key is being pressed. Consequently, if you press N again and again Ohbot will nod again and again. However, in programming this is not the most efficient way to get a robot to perform an instruction multiple times. Have a look around in the Ohbot instructions to see if you can find a more efficient way to perform movements again and again?
We need to use the repeat instruction from the Control palette. Next week we learn to write code using repeat.