Dependencies:   Motor Servo mbed

Committer:
w00Gyy
Date:
Wed Oct 14 03:27:27 2015 +0000
Revision:
0:328a246ec698
Actuator Lab Part 2;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
w00Gyy 0:328a246ec698 1 /* Actuator Lab Part 2
w00Gyy 0:328a246ec698 2 This program demonstrates the simultanious action of 2 servo motors.
w00Gyy 0:328a246ec698 3 The servos rotate opposite to eachother and once they reach their maximum angle of
w00Gyy 0:328a246ec698 4 rotation, they return to the original location.
w00Gyy 0:328a246ec698 5 Written by MIDN 3/C C. Garcia, 13-OCT-15
w00Gyy 0:328a246ec698 6 */
w00Gyy 0:328a246ec698 7
w00Gyy 0:328a246ec698 8 #include "mbed.h"
w00Gyy 0:328a246ec698 9 #include "Servo.h"
w00Gyy 0:328a246ec698 10
w00Gyy 0:328a246ec698 11 Servo myservo(p21); //Servo Pins
w00Gyy 0:328a246ec698 12 Servo myservo1(p22);
w00Gyy 0:328a246ec698 13
w00Gyy 0:328a246ec698 14 int MaxDegrees = 180; //Max rotation
w00Gyy 0:328a246ec698 15 float PW = .0018; //Pulsewidth
w00Gyy 0:328a246ec698 16
w00Gyy 0:328a246ec698 17
w00Gyy 0:328a246ec698 18 int main()
w00Gyy 0:328a246ec698 19 {
w00Gyy 0:328a246ec698 20 float Position = 0.0; //initial position
w00Gyy 0:328a246ec698 21 myservo.calibrate(PW/2, MaxDegrees/2); //servo calibration
w00Gyy 0:328a246ec698 22 myservo1.calibrate(PW/2, MaxDegrees/2);
w00Gyy 0:328a246ec698 23 while(1) {
w00Gyy 0:328a246ec698 24
w00Gyy 0:328a246ec698 25 for(Position = 0; Position <= 1; Position += .05556) { //incriments from 0 to 1 by 10 degrees
w00Gyy 0:328a246ec698 26 myservo = Position;
w00Gyy 0:328a246ec698 27 myservo1 = 1 - Position; //reverses direction of rotation for the second servo
w00Gyy 0:328a246ec698 28 getchar(); //proceeds to the next incriment of the for loop once character is recieved (fancy wait)
w00Gyy 0:328a246ec698 29 }
w00Gyy 0:328a246ec698 30
w00Gyy 0:328a246ec698 31 }
w00Gyy 0:328a246ec698 32
w00Gyy 0:328a246ec698 33 }