Engduino Tutorial
In this tutorial, you will make a program that will allow for interaction between TouchDevelop and
the Engduino. This tutorial will assume that you have completed the Conditional Statements and
Iteration Tutorials.
So what is an Engduino?
The Engduino is a small computer that takes both
inputs and gives outputs. For example, we can create
a program for the Engduino so that the lights will
react to the acceleration of the device.
Before we begin, we will require the Engduino
Library.
Click on
Search
everything,
and type in
“Engduino
Library”.
You should find an entry
created by Michal Moskal. Click
on the Edit button. Now you have access to the Engduino Library
Now let’s begin!
Create a new script with a blank
template, and give it a memorable
name.
We installed the Engduino Library, but we now need this program to be able to access it.
Click on the “add new
action, event” button
and then select library
and finally select
Engduino.
We have the library in the program. In order for the program to be able to do anything, the
Engduino must be started.
Type in Engduino then Init into the main
function
Try running the program now by clicking
Run
The Engduino Library requires us to use the gameloop event. An event will run code whenever, the
event is triggered. In this case, the gameloop event is triggered as soon as the previous gameloop
event has finished.
Let’s explore how this works
Click on “add new
action event”.
Then search for “event” and click on it. Then search
for gameloop and click on that.
Let’s turn the lights on and make it red.
What about making them blink? We need to turn on the lights and turn off the lights. To turn off the
lights, we set the colour to black.
Hang on! Why are the lights black? This is because the gameloop runs so fast that after turning the
lights on to red, the code immediately sets the lights back to off. Let’s add a delay to the code to
make it do what we wanted.
Now the lights blink red. Let’s make the lights change colour depending on if the button is pressed or
not. To do this, we can use if blocks.
This code will make the Engduino blink its lights red if the button is pressed, otherwise it will blink
green
Exercises:
1. Change the colour to blue instead of green in the last example
2. Make the lights blink slower. Hint: The number beside the delay word represents how many
milliseconds the code should wait
3. Modify the code so that the Engduino will turn on the lights to red if the button pressed,
otherwise turn the lights off
Mark Scheme
1.
The child should also try
setting the colour to random
2.
The number inside delay can be
increased as far as the child
likes. The larger the values, the
longer the blink. Encourage the
child to test what happens if
the two delay values are
different
3.
Of course, the colour could
be set to any other colour.
Try setting the colour to
random