Don’t let that button destroy your bot!

Have you every programmed a robot that for example has an arm that goes up with one button (say E-Up) and down with another button (say E-down) but when the arm is up you press up again by mistake and the whole mechanism starts sending the pegs around like bullets and come apart. Let’s avoid this with a tiny little programming help.

We first create a variable, a Boolean to be particular. Boolean is a variable that has 2 values, true or false. We call this variable “isTheArmUp” and when the arm is up, we set it to true and when the arm is down we set it to false. Also in our “When Started” block we should also set it to false because I assume our robots starts with the arm in down position. So an example of this done right could look like this:

To sum this up, we have defined 2 functions. (Read about using my blocks here) One to raise the arm, one to hang with the arm (lower the arm) and when raising is finished we use the orange block where we set this variable to true. On the other code block we set this variable to false. And then on our controller when E up is pressed, it checks the variable first and if it is true it plays “wrong way” sound. I like to use this to teach some good manners to the driver and let them know when they did something wrong. And again when E down is pressed if “isTheArmUp” is true (means arm is up) it will run the hang function to lower the arm, otherwise it will play the “hey watch out” sound again.

That’s it for today, a short little tip that comes in very handy sometimes.

Yas Programmer