Figure 5-10. The actual Arduino-based servo motor controller prototype
To make the servo motor stationary on the solderless breadboard, a small jumper wire is secured across its wiring pigtail, as seen in Figure 5-10 on the right.
Listing 5-1. The Servo Sweep Sketch
// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.
#include<Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
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 < 180; pos += 1) // goes from 0 degrees to
180degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); //waits 15 ms for the servo to reach the position
}
for(pos = 180; 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 15 ms for the servo to reach the position
}
}
The Sweep sketch shown in Listing 5-1 is located in the ArduinoIDE at File→Examples→ Servo→ Sweep. Figure 5-11 shows the Sweep sketch within the Examples directory. When you upload the code to the Arduino computational platform, the servo motor begins to sweep between the established rotational angles of 0° to 180°. As mentioned, this sweep motion is continuous.
Figure 5-11. Obtaining the Sweep sketch within the Arduino-Processing IDE
Physical Computing: A Servo Motor with a Potentiometer
If you add a potentiometer to the servo setup you have now, you can accommodate easy human interaction with the electromechanical components. By adding a potentiometer, manual control of the servo motor is possible. The potentiometer allows the servo motor’s angular position to be dialed in precisely. By rotating the potentiometer’s shaft (wiper arm), the servo motor’s degree of motion can be changed. Discrete angles such as 35°, 45°, 60°, and 110° can easily be dialed in using the potentiometer. The wiring to the Arduino’s PCB inline header connectors is accomplished as shown in Figure 5-12. The circuit schematic diagram is illustrated in Figure 5-13 with the actual prototype shown in Figure 5-14. The sketch for controlling the servo motor with
a potentiometer is obtained from the Arduino-Processing IDE by clicking File → Examples → Servo →Knob. Figure 5-15 shows the Knob sketch within the Examples directory. The Knob sketch is shown in Listing 5-2.
- 上一篇:拉丝机英文文献和中文翻译
- 下一篇:冲压模具英文参考文献和中文翻译
-
-
-
-
-
-
-
浅析中国古代宗法制度
现代简约美式风格在室内家装中的运用
高警觉工作人群的元情绪...
江苏省某高中学生体质现状的调查研究
g-C3N4光催化剂的制备和光催化性能研究
巴金《激流三部曲》高觉新的悲剧命运
C++最短路径算法研究和程序设计
中国传统元素在游戏角色...
NFC协议物理层的软件实现+文献综述
上市公司股权结构对经营绩效的影响研究