2_session_plan-bug-final

advertisement
Bug
Session Two
Bug: Session Two
1
Session description
In this session the use of algorithms is reinforced to help pupils plan out what they
will need to program on their Bug. They are introduced to the idea of a variable and
discover how variables can be used in a program.
Objectives
The students will:
•
•
•
•
•
Use an algorithm to plan a sequence
Use an algorithm to plan a sequence using a variable
Use a variable in a program
Use variables to create patterns
Debug any errors in their program
Session activities summary
• Reinforce use of an algorithm to be implemented as a program
• Discover how a variable can be used to make lines on a Bug
Resources
Bug website
Bug software
Bug
Bug cables
Bug: Session Two
2
Time
Activities
5 minutes
Planning an algorithm
What is an algorithm? (check understanding from previous session)
A set of instructions to achieve a set objective. Make sure pupils understand it is
'planning' what will happen and that the coding or programming is actually 'making it'
happen.
Can you write the algorithm to turn an LED on and off?
Accept any way of recording this; numbered instructions, a flow chart or other way of
recording. Make sure pupils are not actually describing the blocks they used but are
listing the sequence of what happens.
5 minutes
In lesson 1 we have seen that using a repeat block makes our programming
easier. We are now going to find a way to light up a whole row without having to
program each LED light individually.
What does variable mean? - something that changes.
A lot of games keep a 'score' to show you how well you are doing. 'Score' is a
variable.
When you have a spelling test what happens each time you spell a word correctly?
- Your score goes up by one
- Show score as a box
- I’ve got another spelling right what happens to my score?
- Add one to the score (repeat as necessary).
Write this as an algorithm.
Spelling test algorithm
• Set score to 0
• Repeat for the number of words in the test
• Listen to spelling
• Write spelling
• If spelling is correct add 1 to score
Did you know?
There is a Bitesize computing
guide called: What is an
algorithm?
http://www.bbc.co.uk/guides/
z3whpv4#orb-banner
Bug: Session Two
5 minutes
3
We are going to use a variable to make any LED in a row light up.
Teacher demonstrates using set item block (Click on Variables to see these
blocks).
Drag both the 'set item' and 'item' blocks from the Variable menu to the script area
together with the ‘plot’ block from LED menu. Drag the ‘0’value block from the Basic
menu to put in set item block.
Use drop down menu next to item to rename it as 'x'. Our variable that will change is
the 'x'.
What happens when I run this bit of program?
What happens when I change the value of x? – show changing it to any number
between 1 and 4.
10 minutes
Ask the children to create a variable for ' x' and see if they can change it.
Can they find out how to set a variable for y and change it?
Bug: Session Two
10 minutes
4
We can get our Bug to change the variable itself by counting. As it counts the
x variable from 0 to 4, this will light up each LED moving across the row.
Show pupils ‘count with’ block under Loop menu. We have already used the repeat
loop. This is a special kind of repeat loop.
It is counting from 0 to 4 going up in 1s. Each time the count is increased by 1, it
repeats the loop but changes the value of the variable.
What variable do we need to change? The value of the 'x' coordinate.
10 minutes
Challenge: Can you use these blocks to get the top row of LEDs to light up?
Note: Pupils will need to rename item to be 'x'. They can set the 'x' value to '0' – as
they did earlier in the lesson.
Encourage pupils to keep testing what they have done to see if it works.
Provide guidance as needed.
Bug: Session Two
15 minutes
5
Challenge: Can you make different rows of LEDs light up? Can you turn off the row?
What do you need to do to make different columns light up? You will need to make
a variable for 'y' and change the value of 'y'.
What patterns can you create on your Bug?
Pupils will be able to rename the variable 'x' to change it to 'y'. If they want to have
rows and columns drawn in the same pattern they will need to add a new variable.
Go to Variables. Get a ‘set item’ block and choose new variable from the drop down
menu.
Encourage pupils to look at each other’s patterns and ask for help from their peers.
5 minutes
Download your pattern to your Bug.
See session one.
Download