The MagPi Issue 18

Page 14

Example 3: Making a Motor Run

The fun thing about robotics is that its not just taking sensor data, its moving. In this last example we will show you how to make a motor move, and how to control it from a keyboard. In this example we will use Motor A on the BrickPi. Connect a LEGO速 Mindstroms motor to motor port MA.

So let us take a look at how to use the colour sensor. Open the example Scratch program Color Sensor test. This program is slightly simpler than the first

example. The program starts by associating the S1 sensor port with COLOR. Then the connection with the COLOR sensor is established. The loop continues forever, checking for updates from the sensor. The colour value from the sensor is then used to change the costume of the Scratch cat. To avoid the Scratch cat from being constantly updated while the colour sensor remains pointing at the same colour, there is a wait statement. Now try running the program and position the colour sensor over each of the colours.

14

Now with the motor attached, let us look at an example of moving the motor. Open up the example program Motor test. Unlike the sensors, we do not have to setup anything before using the motors. We can just start using them; nothing other than the motors should go on the motor ports. So let us look at how to make a motor do just one thing.


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.