DC motor and Servo
Dependencies: DC_Motor Servo mbed
Fork of Lab2_41 by
main.cpp
- Committer:
- m211656
- Date:
- 2018-10-11
- Revision:
- 2:ecf535666eb3
- Parent:
- 1:88e499bfdcc7
File content as of revision 2:ecf535666eb3:
//Lab2_4 //Code demonstrates how to use outputs and inputs within a loop //Written by: MIDN 3/C Caicedo and MIDN 3/C Eckert //Modified: // 9/27/18 Eckert and Caicedo. Program created // 10/1/18 Caicedo. Modified servo portion of code // 10/3/18 Eckert. Added DC motor into servo motor coding #include "mbed.h" #include "Servo.h" #include "Motor.h" Servo myservo(p21); //pin associated with first servo motor Servo myservo2(p22); // pin associated with second servo motor Motor m(p26,p29,p30); //pins associated with DC motor float i; //variable for servo motor control float f; //variable for DC motor control int main() { myservo.calibrate(0.0009,90); //servo calibration myservo2.calibrate(0.0009, 90); while(1) { for(f=.2; f<=1; f+=.1) { //for loop controlling DC motor m.speed(f); //speed of DC motor printf("speed is %f\n\r", f); //print statement to ensure speed of motor is correct for( i=0; i<180; i++) { //for loop controlling first part of servo motor motion myservo = i/180.0; //first servo moves forward myservo2=(180.0-i)/180.0; //second servo moves opposite wait(.025); } m.speed(-f); //direction of DC motor changes printf("speed is - %f\n\r", f); for( i=180; i>0; i--) {//loop controlling return of servo motors myservo = i/180.0; myservo2=(180.0-i)/180.0; wait(.025); } } } }