Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using the servo library living with the lab Libraries are computer programs written to add functionality to Arduino programs. A library to control hobby.

Similar presentations


Presentation on theme: "Using the servo library living with the lab Libraries are computer programs written to add functionality to Arduino programs. A library to control hobby."— Presentation transcript:

1 using the servo library living with the lab Libraries are computer programs written to add functionality to Arduino programs. A library to control hobby servos is included by default in the Arduino IDE... you already have this library on your computer. A host of libraries are available for Arduino, some must be downloaded separately. See www.arduino.cc/en/Reference/Libraries for some of the available libraries.www.arduino.cc/en/Reference/Libraries © 2012 David Hall

2 living with the lab 2 The content of this presentation is for informational purposes only and is intended only for students attending Louisiana Tech University. The author of this information does not make any claims as to the validity or accuracy of the information or methods presented. Any procedures demonstrated here are potentially dangerous and could result in injury or damage. Louisiana Tech University and the State of Louisiana, their officers, employees, agents or volunteers, are not liable or responsible for any injuries, illness, damage or losses which may result from your using the materials or ideas, or from your performing the experiments or procedures depicted in this presentation. If you do not agree, then do not view this content. The copyright label, the Louisiana Tech logo, and the “living with the lab” identifier should not be removed from this presentation. You may modify this work for your own purposes as long as attribution is clearly provided. DISCLAIMER & USAGE

3 review – manual creation of pulses 3 living with the lab void loop() { digitalWrite(3, HIGH); delayMicroseconds(1700); // hold pin 3 high for 1700ms or 1.7ms digitalWrite(3, LOW); // hold pin 3 low for 20ms delay(20); } these lines of code make the servo go full speed counter clockwise time (milliseconds) voltage (V) 5V - 0V - 20ms full speed clockwise full speed counter clockwise pulse width varies between 1.3ms and 1.7ms pulse width (μs) servo action 1300full speed CW 1400½ speed CW 1500stopped 1600½ speed CCW 1700full speed CCW

4 using the servo library living with the lab #include Servo myservo1; void setup() { myservo1.attach(2); myservo1.writeMicroseconds(1700); } void loop() { } void setup(){ pinMode(2,OUTPUT); } void loop() { digitalWrite(2, HIGH); delayMicroseconds(1700); digitalWrite(2, LOW); delay(20); } both programs below cause a servo attached to pin 2 to continuously spin full speed CCW put this statement in your program to use library... don’t forget the space “declare” the name of your servo as “myservo1”... can choose any name indicate that servo will be wired to pin 2 send a pulse of 1700 μs or 1.7ms out pin 2 this program continues to send pulses to the servo so that it continues to run almost all of the execution time is spent on the delay(20) function... and you can’t do anything else while this is happening writeMicroseconds(1700) continues to send pulses to the servo unless the myservo1.detach() function is called you could also send writeMicroseconds(1500) to stop the motion of the servo without detaching it when using the servo library, you can do other things, like check whisker status, while the servo is running 4


Download ppt "Using the servo library living with the lab Libraries are computer programs written to add functionality to Arduino programs. A library to control hobby."

Similar presentations


Ads by Google