First Programs: 2. Events
The intelino train uses its sensors to interact with its environment, including you, the track, etc. Such sensory interactions are called events and the train instantly sends out notifications the moment such events occur. Scratch can listen for different types of event notifications as they arrive from the train. And you can use Scratch to program different actions depending on the event type received. Such a programming approach is called event-based programming and it is suited perfectly for controlling robotic devices such as the intelino smart train.
Let's give it a try! Power on your train and connect it to intelino Scratch. Find the 'when movement' block and drag it onto the workspace. Also find the 'set [top LED] hue to' block and attach it below the 'when movement' block. Set the color hue value to 33 which corresponds to green.
Now short press the train's power button to turn on the motor. You should see the top LED light up in green because by pressing the button you changed the movement state to 'forward'.
Let's expand a little on this program. Right click on your program and click on Duplicate. Of course, you can also create this duplicate by dragging new blocks into the workspace, just like you did earlier. In the duplicate program, let's set the 'when movement' block's value to 'stopped' by clicking on the drop-down list. And set the hue value in the color block to 0 which corresponds to red. Your updated program in the workspace should look like this:
Now, let's test it. Just like before, short pressing the train's power button should turn on the motor and light the top LED in green color. But if you press the button again, the movement will stop and the LED will turn red, just like we programmed! You can press the button as often as you like and you will see the LED color change with the movement state.
Now that you understand the basics of even-based programming, you can easily expand on this program and try other ideas of your own.
Next Article: First Programs: 3. Distance
Previous Article: First Programs: 1. Driving