初始化提交
This commit is contained in:
31
arduino-cli/libraries/Servo/examples/Sweep/Sweep.ino
Normal file
31
arduino-cli/libraries/Servo/examples/Sweep/Sweep.ino
Normal file
@@ -0,0 +1,31 @@
|
||||
/* Sweep
|
||||
by BARRAGAN <http://barraganstudio.com>
|
||||
This example code is in the public domain.
|
||||
|
||||
modified 8 Nov 2013
|
||||
by Scott Fitzgerald
|
||||
https://www.arduino.cc/en/Tutorial/LibraryExamples/Sweep
|
||||
*/
|
||||
|
||||
#include <Servo.h>
|
||||
|
||||
Servo myservo; // create servo object to control a servo
|
||||
// twelve servo objects can be created on most boards
|
||||
|
||||
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 180 degrees
|
||||
// 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 >= 0; 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
|
||||
}
|
||||
}
|
||||
29
arduino-cli/libraries/Servo/examples/Sweep/readme.md
Normal file
29
arduino-cli/libraries/Servo/examples/Sweep/readme.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Sweep
|
||||
|
||||
Sweeps the shaft of a RC [servo motor](http://en.wikipedia.org/wiki/Servo_motor#RC_servos) back and forth across 180 degrees.
|
||||
|
||||
## Hardware Required
|
||||
|
||||
* Arduino Board
|
||||
* Servo Motor
|
||||
* Hook-up wires
|
||||
|
||||
## Circuit
|
||||
|
||||
Servo motors have three wires: power, ground, and signal. The power wire is typically red, and should be connected to the 5V pin on the Arduino board. The ground wire is typically black or brown and should be connected to a ground pin on the board. The signal pin is typically yellow, orange or white and should be connected to pin 9 on the board.
|
||||
|
||||

|
||||
|
||||
(Images developed using Fritzing. For more circuit examples, see the [Fritzing project page](http://fritzing.org/projects/))
|
||||
|
||||
## Schematic
|
||||
|
||||

|
||||
|
||||
## See also
|
||||
|
||||
* [attach()](/docs/api.md#attach)
|
||||
* [write()](/docs/api.md#write)
|
||||
* [map()](https://www.arduino.cc/en/Reference/Map)
|
||||
* [Servo library reference](/docs/readme.md)
|
||||
* [Knob](../Knob) - Control the position of a servo with a potentiometer
|
||||
Reference in New Issue
Block a user