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.
上一篇:拉丝机英文文献和中文翻译
下一篇:冲压模具英文参考文献和中文翻译

旋转式伺服电机的柔性电...

智能城市物流云计算模型英文文献和中文翻译

云计算服务英文文献和中文翻译

直流电机英文文献和中文翻译

电-气动驱动的垂直计算机...

金属板料冲压模具计算机...

计算机辅助工艺规划CAPP系...

压疮高危人群的标准化中...

基于Joomla平台的计算机学院网站设计与开发

从政策角度谈黑龙江對俄...

STC89C52单片机NRF24L01的无线病房呼叫系统设计

提高教育质量,构建大學生...

上海居民的社会参与研究

浅谈高校行政管理人员的...

AES算法GPU协处理下分组加...

浅论职工思想政治工作茬...

酵母菌发酵生产天然香料...