Download presentation
Presentation is loading. Please wait.
Published byJonah Short Modified over 8 years ago
1
Robotics Grant Agreement No 518656-LLP-1-2011-1-UK-LEONARDO-LMP Project acronym: CLEM Project title: Cloud services for E-Learning in Mechatronics Technology
2
Mobile robots with Arduino –Exercise 1 Grant Agreement No 518656-LLP-1-2011-1-UK-LEONARDO-LMP Project acronym: CLEM Project title: Cloud services for E-Learning in Mechatronics Technology
3
Mobile robots with Arduino Materials needed 1 x Arduino uno/duemilanove. The Arduino Uno is a microcontroller board based on the ATmega328. Fig. 2: Arduino Uno
4
Mobile robots with Arduino Materials needed 1 x Standard servo Fig. 3: Servo
5
Mobile robots with Arduino Exercise 1. Blink a LED /* * Blink * * The basic Arduino example. Turns on an LED on for one second, * then off for one second, and so on... We use pin 13 because, * depending on your Arduino board, it has either a built-in LED * or a built-in resistor so that you need only an LED. * */
6
Mobile robots with Arduino Exercise 1. Blink a LED void setup() { pinMode(13, OUTPUT); } void loop() { digitalWrite(13, HIGH); delay(1000); digitalWrite(13, LOW); delay(1000); }
7
Mobile robots with Arduino Exercise 1. Blink a LED A variable is a place for storing a piece of data. It has a name, a type, and a value. For example, the line from the Blink sketch above declares a variable with the name ledPin, the type int, and an initial value of 13. It's being used to indicate which Arduino pin the LED is connected to. Every time the name ledPin appears in the code, its value will be retrieved. In this case, the person writing the program could have chosen not to bother creating the ledPin variable and instead have simply written 13 everywhere they needed to specify a pin number. The advantage of using a variable is that it's easier to move the LED to a different pin: you only need to edit the one line that assigns the initial value to the variable.
8
Mobile robots with Arduino Exercise 2. Servo control
9
Mobile robots with Arduino Exercise 2. Servo control #include Servo myservo; // create servo object to control a servo int pos = 0; // variable to store the servo position void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object } void loop() { for(pos = 0; pos =1; pos-=1) // goes from 180 degrees to 0 degrees { myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.