Sequence 1 - Lesson 2: Key Moves
Learning Intention
I can program a robot to carry out a sequence of movements when a key is pressed.
I can program a robot to carry out a sequence of movements when a key is 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 Picoh 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 Picoh 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 to bring Picoh 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.
File, Save As - keyboardNandS
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 to bring Picoh 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.
File, Save As - keyboardNandS
Activity
Can you write some code to use the keyboard to control my pupils?
Can you write some code to use the keyboard to control my pupils?
- U to look up, down then centre
- L to look left, right then centre
Extension
Can you write some code to use the keyboard to control my lips?
Can you write some code to use the keyboard to control my lips?
- Up arrow key to smile for one second
- Down arrow key to frown for one second
Plenary
When we use the keyboard to control Picoh, Picoh’s head will run a sequence only if a key is being pressed. Although this is often a good way for a system to work (such as for the doors on a train that might require a human to check that it is safe for the train to leave), sometimes we may want the robot to carry out actions over and over again without needing a human to start it each time. Have a look at the code blocks to see if you can find a way of performing movements again and again without needing a human to press the key?
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 Picoh, Picoh’s head will run a sequence only if a key is being pressed. Although this is often a good way for a system to work (such as for the doors on a train that might require a human to check that it is safe for the train to leave), sometimes we may want the robot to carry out actions over and over again without needing a human to start it each time. Have a look at the code blocks to see if you can find a way of performing movements again and again without needing a human to press the key?
We need to use the repeat instruction from the Control palette. Next week we learn to write code using repeat.