CarletonExamples

From ArduinoInfo
Jump to: navigation, search

Example Sketches and Notes for Carleton College


Servo_5_Sweep Sketch:

Runs 5 servos attached to pins 8-9-10-11-12 through 180 degrees, medium then fast.

RedBack Controller input current to external power connector:

9V 1 A Power Supply 0.5 Amps
12V 2 A Power Supply 0.3 Amps

Cut and paste following sketch into an Arduino IDE window.
/* YourDuinoStarter Example: 5 Servos Sweep - WHAT IT DOES Sweeps 5 servos on pins 8-9-10-11-12 through 180 degrees - SEE the comments after "//" on each line below - CONNECTIONS: - Servos on 3-pin connectors on YourDuinoRobo1 or RedBack - MUST use External Power connector and 9 to 12V power supply - V1.00 12/09/2013 Questions: terry@yourduino.com */ /*-----( Import needed libraries )-----*/ #include <Servo.h> /*-----( Declare Constants and Pin Numbers )-----*/ /*-----( Declare objects )-----*/ Servo servo1; // create servo object to control a servo Servo servo2; Servo servo3; Servo servo4; Servo servo5; /*-----( Declare Variables )-----*/ int pos = 0; // variable to store the servo position void setup() /****** SETUP: RUNS ONCE ******/ { servo1.attach(8); // Attach servos on pins to Servo Objects servo2.attach(9); servo3.attach(10); servo4.attach(11); servo5.attach(12); }//--(end setup )--- void loop() /****** LOOP: RUNS CONSTANTLY ******/ { for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees { // in steps of 1 degree servo1.write(pos); // tell servo to go to position in variable 'pos' servo2.write(pos); servo3.write(pos); servo4.write(pos); servo5.write(pos); delay(15); // waits 15ms for the servo to reach the position } for(pos = 180; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees { servo1.write(pos); // tell servo to go to position in variable 'pos' servo2.write(pos); servo3.write(pos); servo4.write(pos); servo5.write(pos); delay(5); // waits 15ms for the servo to reach the position } }//--(end main loop )--- /*-----( Declare User-written Functions )-----*/ //none
//*********( THE END )***********