add servos

Dependencies:   Servo1 mbed

Fork of ES200_Project2 by Project 2

Committer:
m211656
Date:
Thu Oct 18 19:10:52 2018 +0000
Revision:
1:852f86d263c8
Parent:
0:b6a454c0b00a
Add servos

Who changed what in which revision?

UserRevisionLine numberNew contents of line
m211656 0:b6a454c0b00a 1 #include "mbed.h"
m211656 0:b6a454c0b00a 2 #include "Servo.h"
m211656 0:b6a454c0b00a 3 #include "Motor.h"
m211656 0:b6a454c0b00a 4
m211656 0:b6a454c0b00a 5 Servo myservo(p21);
m211656 0:b6a454c0b00a 6 Servo myservo2(p22);
m211656 0:b6a454c0b00a 7 Motor m(p26,p30,p29);
m211656 1:852f86d263c8 8 DigitalIn sw1(p15), sw2(p16), sw3(p17), sw4(p18), sw5(p19);
m211656 1:852f86d263c8 9 BusOut lights(p5,p6,p7,p10,p11);
m211656 0:b6a454c0b00a 10
m211656 0:b6a454c0b00a 11
m211656 0:b6a454c0b00a 12 int main()
m211656 0:b6a454c0b00a 13 {
m211656 0:b6a454c0b00a 14 while(1)
m211656 0:b6a454c0b00a 15 {
m211656 1:852f86d263c8 16 wait(0.5);
m211656 1:852f86d263c8 17 if(sw5==1) { //servo1 off
m211656 1:852f86d263c8 18 lights=31;
m211656 1:852f86d263c8 19 printf("light 5 is on\n\r");
m211656 0:b6a454c0b00a 20 }
m211656 1:852f86d263c8 21 else if(sw4==1) { //dc motor off
m211656 1:852f86d263c8 22 lights=15;
m211656 1:852f86d263c8 23 printf("light 4 is on\n\r");
m211656 1:852f86d263c8 24 m.speed(0.0);
m211656 0:b6a454c0b00a 25 }
m211656 1:852f86d263c8 26 else if(sw3==1) { //servo2 on
m211656 0:b6a454c0b00a 27 lights=7;
m211656 1:852f86d263c8 28 printf("light 3 is on\n\r");
m211656 0:b6a454c0b00a 29 }
m211656 1:852f86d263c8 30 else if(sw2==1) { //dc motor on
m211656 1:852f86d263c8 31 lights=3;
m211656 1:852f86d263c8 32 printf("light 2 is on\n\r");
m211656 1:852f86d263c8 33 m.speed(1.0);
m211656 0:b6a454c0b00a 34 }
m211656 1:852f86d263c8 35 else if(sw1==1) { //servo1 comes on
m211656 1:852f86d263c8 36 lights=1;
m211656 1:852f86d263c8 37 printf("light 1 is on\n\r");
m211656 0:b6a454c0b00a 38 }
m211656 0:b6a454c0b00a 39 else {
m211656 1:852f86d263c8 40 lights=0; //no switches on = no lights or motors on
m211656 1:852f86d263c8 41 m.speed(0.0);}
m211656 0:b6a454c0b00a 42
m211656 0:b6a454c0b00a 43 }
m211656 0:b6a454c0b00a 44 }