keyestudio
www.keyestudio.cc
135
pinMode(servopin,OUTPUT);// set servo pin as “output”
Serial.begin(9600);// connect to serial port, set baud rate at “9600”
Serial.println("servo=o_seral_simple ready" ) ;
}
void loop()// convert number 0 to 9 to corresponding 0-180 degree angle, LED blinks
corresponding number of time
{
val=Serial.read();// read serial port value
if(val>'0'&&val<='9')
{
val=val-'0';// convert characteristic quantity to numerical variable
val=val*(180/9);// convert number to angle
Serial.print("moving servo to ");
Serial.print(val,DEC);
Serial.println();
for(int i=0;i<=50;i++) // giving the servo time to rotate to commanded position
{
servopulse(servopin,val);// use the pulse function
}
}
}
//////////////////////////////////////////////////////////
Method 2:
Let's first take a look at the Arduino built-in servo function and some of its common statements.
1. attach
(
interface
)
——select pin for servo, can only use pin 9 or 10.
2. write
(
angle
)
——used to control the rotate angle of the servo, can set the angle among 0 degree
to 180 degree.
3. read
()
——used to read the angle of the servo, consider it a function to read the value in
the write() function.
4
、
attached
()
——determine whether the parameter of the servo is sent to the servo pin.
5
、
detach
()
—— disconnect the servo and the pin, and the pin(digital pin 9 or 10) can be used for
PWM port.
Note: Note: the written form of the above statements are " servo variable name. specific statement
()", e.g. myservo. Attach (9).
Still, connect the servo to pin 9.
Sample program B
:
//////////////////////////////////////////////////////////
#include <Servo.h>// define a header file. Special attention here, you can call the servo function
directly from Arduino's software menu
bar Sketch>Importlibrary>Servo, or input #include <Servo.h>. Make sure there is a space
Содержание ARDUINO maker learning kit
Страница 1: ...keyestudio www keyestudio cc ARDUINO maker learning kit...
Страница 23: ...keyestudio www keyestudio cc 21 Connection for 2560 R3...
Страница 30: ...keyestudio www keyestudio cc 28 Connection for 2560 R3...
Страница 39: ...keyestudio www keyestudio cc 37 Connection for 2560 R3...
Страница 43: ...keyestudio www keyestudio cc 41 Connection for 2560 R3...
Страница 46: ...keyestudio www keyestudio cc 44 Connection for 2560 R3...
Страница 50: ...keyestudio www keyestudio cc 48 Connection for 2560 R3...
Страница 53: ...keyestudio www keyestudio cc 51 Connection circuit as below Connection for R3 Connection for 2560 R3...
Страница 58: ...keyestudio www keyestudio cc 56 Connection for 2560 R3...
Страница 62: ...keyestudio www keyestudio cc 60 Connection for 2560 R3...
Страница 65: ...keyestudio www keyestudio cc 63 Circuit connection Connection for R3...
Страница 66: ...keyestudio www keyestudio cc 64 Connection for 2560 R3...
Страница 69: ...keyestudio www keyestudio cc 67 Pic 2 Project 15 LM35 temperature sensor...
Страница 71: ...keyestudio www keyestudio cc 69 Connection for 2560 R3 Sample program...
Страница 74: ...keyestudio www keyestudio cc 72 Schematic diagram...
Страница 77: ...keyestudio www keyestudio cc 75 Circuit connection Connection for R3...
Страница 78: ...keyestudio www keyestudio cc 76 Connection for 2560 R3...
Страница 80: ...keyestudio www keyestudio cc 78 Result...
Страница 82: ...keyestudio www keyestudio cc 80 Connection for 2560 R3...
Страница 85: ...keyestudio www keyestudio cc 83 Schematic diagram Circuit connection Connection for R3...
Страница 91: ...keyestudio www keyestudio cc 89 Circuit connection Connection for R3...
Страница 92: ...keyestudio www keyestudio cc 90 Connection for 2560 R3...
Страница 95: ...keyestudio www keyestudio cc 93...
Страница 96: ...keyestudio www keyestudio cc 94...
Страница 104: ...keyestudio www keyestudio cc 102 Connection for 2560 R3...
Страница 111: ...keyestudio www keyestudio cc 109 Connection for R3 Connection for 2560 R3...
Страница 120: ...keyestudio www keyestudio cc 118 Connection for 2560 R3...
Страница 124: ...keyestudio www keyestudio cc 122 Connection for R3 Connection for 2560 R3...
Страница 135: ...keyestudio www keyestudio cc 133 Connection for R3 Connection for 2560 R3...
Страница 139: ...keyestudio www keyestudio cc 137 Circuit connection Connection for uno R3...
Страница 140: ...keyestudio www keyestudio cc 138 Connection for 2560 R3...
Страница 144: ...keyestudio www keyestudio cc 142 Circuit connection Connection for R3...
Страница 145: ...keyestudio www keyestudio cc 143 Connection for 2560 R3...
Страница 148: ...keyestudio www keyestudio cc 146 Connection for 2560 R3 Sample program...
Страница 155: ...keyestudio www keyestudio cc 153 Circuit connection Connection for R3...
Страница 156: ...keyestudio www keyestudio cc 154 Connection for 2560 R3...
Страница 160: ...keyestudio www keyestudio cc 158 Connection for 2560 R3...