I’m often asked what ‘variables’ are and how are they useful? How would I go about teaching them in class? Well the question was raised again this week on our Robotics in Education Mailing list so I thought I’d do a very quick blog post on how I approach it.
Count the number of times a button is pressed and display on the screen. (click for large version)
Basically the program is as follows
- Write a ‘0’ to the ‘count’ variable (just in case it was something else)
- Wait for someone to bump the touch sensor (not push)
- Take the variable -> Add 1 to it -> store the new number back in the variable
- Display the variable number on the screen
- Loop back to wait for the next button press
Ask the kids why they don’t see the ‘0’ when the program starts, but do see the ‘1’ the first time the button is pressed. Ask them to fix it up so they see a 0.
We then take this and add another button and make a voting machine. Do you like Chocolate or Vanilla Icecream? This is then a great lead in for statistics etc 🙂
5 Comments
Comments are closed.
Gracias por compartir sus conocimientos, desde Bolivia estamos muy agradecidos
How do you make a colour as a variable?
I tried to do this and it didn't work…
Hy Rhys,
Use the 'Display' blcok and set the input field (top right part of the block) to be 'Wired'. You'll then get an extra input box (bottom left) that you can send the variable wire to.
How do you display the value of the variables?