a

Dependencies:   mbed MotorDriver_SU

Committer:
12f2029h
Date:
Fri Nov 07 06:55:00 2014 +0000
Revision:
3:e54506c893b7
Parent:
2:b1498967bcb4
Child:
4:02c4de3930a2
a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
12f2029h 1:b9a97697a48b 1 #include "mbed.h"
12f2029h 1:b9a97697a48b 2 #include "MotorDriver_SU.h"
12f2029h 1:b9a97697a48b 3
12f2029h 1:b9a97697a48b 4 DigitalIn sensor1(P1_21);
12f2029h 1:b9a97697a48b 5 DigitalIn sensor2(P0_21);
12f2029h 1:b9a97697a48b 6 DigitalIn sensor3(P0_12);
12f2029h 1:b9a97697a48b 7 DigitalIn sensor4(P0_13);
12f2029h 1:b9a97697a48b 8 MotorDriver_SU motor(MOTOR_DOUBLE);
12f2029h 1:b9a97697a48b 9 MotorDriver_SU lift(MOTOR_SINGLE);
12f2029h 1:b9a97697a48b 10
12f2029h 1:b9a97697a48b 11 int main(){
12f2029h 1:b9a97697a48b 12 int x = 0;
12f2029h 1:b9a97697a48b 13
12f2029h 1:b9a97697a48b 14 while(1){
12f2029h 1:b9a97697a48b 15 if(sensor1 == 0 && sensor2 == 0){
12f2029h 1:b9a97697a48b 16 motor.Drive(0,CW,1500);
12f2029h 1:b9a97697a48b 17 motor.Drive(1,CW,1500);
12f2029h 1:b9a97697a48b 18 }
12f2029h 1:b9a97697a48b 19 else if(sensor1 == 0 && sensor2 == 1){
12f2029h 1:b9a97697a48b 20 x = 1;
12f2029h 1:b9a97697a48b 21 motor.Drive(0,CW,0);
12f2029h 1:b9a97697a48b 22 motor.Drive(1,CW,1500);
12f2029h 1:b9a97697a48b 23 }
12f2029h 1:b9a97697a48b 24 else if(sensor1 == 1 && sensor2 == 0){
12f2029h 1:b9a97697a48b 25 x = 2;
12f2029h 1:b9a97697a48b 26 motor.Drive(0,CW,1500);
12f2029h 1:b9a97697a48b 27 motor.Drive(1,CW,0);
12f2029h 1:b9a97697a48b 28 }
12f2029h 1:b9a97697a48b 29 else if(x == 1 && sensor1 == 1 && sensor2 == 1){
12f2029h 1:b9a97697a48b 30
12f2029h 1:b9a97697a48b 31 motor.Drive(0,CW,0);
12f2029h 1:b9a97697a48b 32 motor.Drive(1,CW,1500);
12f2029h 1:b9a97697a48b 33 }
12f2029h 1:b9a97697a48b 34 else if(x == 2 && sensor1 == 1 && sensor2 == 1){
12f2029h 1:b9a97697a48b 35 motor.Drive(0,CW,1500);
12f2029h 1:b9a97697a48b 36 motor.Drive(1,CW,0);
12f2029h 1:b9a97697a48b 37 }
12f2029h 1:b9a97697a48b 38 else if(sensor3 == 0 && sensor4 == 0){
12f2029h 3:e54506c893b7 39 lift.Drive(0,CW,1500);
12f2029h 1:b9a97697a48b 40 motor.Drive(0,CW,0);
12f2029h 1:b9a97697a48b 41 motor.Drive(1,CW,0);
12f2029h 3:e54506c893b7 42 break;
12f2029h 1:b9a97697a48b 43 }
12f2029h 1:b9a97697a48b 44 }
12f2029h 1:b9a97697a48b 45 while(1){
12f2029h 1:b9a97697a48b 46 if(sensor1 == 0 && sensor2 == 0){
12f2029h 1:b9a97697a48b 47 motor.Drive(0,CW,1500);
12f2029h 1:b9a97697a48b 48 motor.Drive(1,CW,1500);
12f2029h 1:b9a97697a48b 49 }
12f2029h 1:b9a97697a48b 50 else if(sensor1 == 0 && sensor2 == 1){
12f2029h 1:b9a97697a48b 51 x = 1;
12f2029h 1:b9a97697a48b 52 motor.Drive(0,CW,0);
12f2029h 1:b9a97697a48b 53 motor.Drive(1,CW,1500);
12f2029h 1:b9a97697a48b 54 }
12f2029h 1:b9a97697a48b 55 else if(sensor1 == 1 && sensor2 == 0){
12f2029h 1:b9a97697a48b 56 x = 2;
12f2029h 1:b9a97697a48b 57 motor.Drive(0,CW,1500);
12f2029h 1:b9a97697a48b 58 motor.Drive(1,CW,0);
12f2029h 1:b9a97697a48b 59 }
12f2029h 1:b9a97697a48b 60 else if(x == 1 && sensor1 == 1 && sensor2 == 1){
12f2029h 1:b9a97697a48b 61
12f2029h 1:b9a97697a48b 62 motor.Drive(0,CW,0);
12f2029h 1:b9a97697a48b 63 motor.Drive(1,CW,1500);
12f2029h 1:b9a97697a48b 64 }
12f2029h 1:b9a97697a48b 65 else if(x == 2 && sensor1 == 1 && sensor2 == 1){
12f2029h 1:b9a97697a48b 66 motor.Drive(0,CW,1500);
12f2029h 1:b9a97697a48b 67 motor.Drive(1,CW,0);
12f2029h 1:b9a97697a48b 68 }
12f2029h 1:b9a97697a48b 69 else if(sensor3 == 0 && sensor4 == 0){
12f2029h 1:b9a97697a48b 70 lift.Drive(0,CCW,1500);
12f2029h 1:b9a97697a48b 71 motor.Drive(0,CW,0);
12f2029h 1:b9a97697a48b 72 motor.Drive(1,CW,0);
12f2029h 1:b9a97697a48b 73 }
12f2029h 1:b9a97697a48b 74 }
12f2029h 3:e54506c893b7 75 }
12f2029h 3:e54506c893b7 76