a

Dependencies:   mbed MotorDriver_SU

Committer:
12f2029h
Date:
Fri Nov 07 06:48:09 2014 +0000
Revision:
2:b1498967bcb4
Parent:
1:b9a97697a48b
Child:
3:e54506c893b7
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 1:b9a97697a48b 39 moter.Lift(0,CW,1500);
12f2029h 1:b9a97697a48b 40 motor.Drive(0,CW,0);
12f2029h 1:b9a97697a48b 41 motor.Drive(1,CW,0);
12f2029h 1:b9a97697a48b 42 breake;
12f2029h 1:b9a97697a48b 43 }
12f2029h 1:b9a97697a48b 44 }
12f2029h 1:b9a97697a48b 45 }
12f2029h 1:b9a97697a48b 46 while(1){
12f2029h 1:b9a97697a48b 47 if(sensor1 == 0 && sensor2 == 0){
12f2029h 1:b9a97697a48b 48 motor.Drive(0,CW,1500);
12f2029h 1:b9a97697a48b 49 motor.Drive(1,CW,1500);
12f2029h 1:b9a97697a48b 50 }
12f2029h 1:b9a97697a48b 51 else if(sensor1 == 0 && sensor2 == 1){
12f2029h 1:b9a97697a48b 52 x = 1;
12f2029h 1:b9a97697a48b 53 motor.Drive(0,CW,0);
12f2029h 1:b9a97697a48b 54 motor.Drive(1,CW,1500);
12f2029h 1:b9a97697a48b 55 }
12f2029h 1:b9a97697a48b 56 else if(sensor1 == 1 && sensor2 == 0){
12f2029h 1:b9a97697a48b 57 x = 2;
12f2029h 1:b9a97697a48b 58 motor.Drive(0,CW,1500);
12f2029h 1:b9a97697a48b 59 motor.Drive(1,CW,0);
12f2029h 1:b9a97697a48b 60 }
12f2029h 1:b9a97697a48b 61 else if(x == 1 && sensor1 == 1 && sensor2 == 1){
12f2029h 1:b9a97697a48b 62
12f2029h 1:b9a97697a48b 63 motor.Drive(0,CW,0);
12f2029h 1:b9a97697a48b 64 motor.Drive(1,CW,1500);
12f2029h 1:b9a97697a48b 65 }
12f2029h 1:b9a97697a48b 66 else if(x == 2 && sensor1 == 1 && sensor2 == 1){
12f2029h 1:b9a97697a48b 67 motor.Drive(0,CW,1500);
12f2029h 1:b9a97697a48b 68 motor.Drive(1,CW,0);
12f2029h 1:b9a97697a48b 69 }
12f2029h 1:b9a97697a48b 70 else if(sensor3 == 0 && sensor4 == 0){
12f2029h 1:b9a97697a48b 71 lift.Drive(0,CCW,1500);
12f2029h 1:b9a97697a48b 72 motor.Drive(0,CW,0);
12f2029h 1:b9a97697a48b 73 motor.Drive(1,CW,0);
12f2029h 1:b9a97697a48b 74 }
12f2029h 1:b9a97697a48b 75 }
12f2029h 1:b9a97697a48b 76 }