PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
libArduino
tests
ServoTest
ServoTest.cpp
1
// Sweep
2
// by BARRAGAN <http://barraganstudio.com>
3
// This example code is in the public domain.
4
5
#include <Arduino.h>
6
#include <stdio.h>
7
#include <Servo.h>
8
9
Servo
myservo;
// create servo object to control a servo
10
// a maximum of eight servo objects can be created
11
12
Servo
myservo2;
// create servo object to control a servo
13
// a maximum of eight servo objects can be created
14
15
int
pos = 0;
// variable to store the servo position
16
17
void
setup()
18
{
19
delay(1000);
20
printf(
"In setup about to attach servo.\n"
);
21
myservo.attach(12);
// attaches the servo on pin 16 to the servo object
22
myservo2.attach(13);
// attaches the servo on pin 16 to the servo object
23
}
24
25
void
loop()
26
{
27
printf(
"\nin loop about to sweep servo up.\n"
);
28
29
for
(pos = 0; pos < 180; pos += 1)
// goes from 0 degrees to 180 degrees
30
{
// in steps of 1 degree
31
myservo.write(pos);
// tell servo to go to position in variable 'pos'
32
myservo2.write(pos);
// tell servo to go to position in variable 'pos'
33
delay(20);
// waits 15ms for the servo to reach the position
34
printf(
"pos = %d.\n"
, myservo.read());
35
}
36
37
printf(
"\nin loop about to sweep servo down.\n"
);
38
for
(pos = 180; pos>=1; pos-=1)
// goes from 180 degrees to 0 degrees
39
{
40
myservo.write(pos);
// tell servo to go to position in variable 'pos'
41
myservo2.write(pos);
// tell servo to go to position in variable 'pos'
42
delay(20);
// waits 15ms for the servo to reach the position
43
printf(
"pos = %d.\n"
, myservo.read());
44
}
45
}
Servo
Definition:
Servo.h:41
Generated on Fri May 20 2022 16:48:01 for PropWare by
1.8.17