Main

Committer:
chinetion
Date:
Tue Dec 08 18:33:16 2015 +0000
Revision:
2:8441bd03d9bc
Parent:
1:0b8836a7cd96
last

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chinetion 0:57b3f673b395 1 class MOTOR{
chinetion 0:57b3f673b395 2 public:
chinetion 0:57b3f673b395 3 MOTOR(PinName,PinName);
chinetion 0:57b3f673b395 4 void forward();
chinetion 0:57b3f673b395 5 void backward();
chinetion 0:57b3f673b395 6 void stop();
chinetion 1:0b8836a7cd96 7 void read();
chinetion 0:57b3f673b395 8 private:
chinetion 0:57b3f673b395 9 DigitalOut a;
chinetion 0:57b3f673b395 10 DigitalOut b;
chinetion 1:0b8836a7cd96 11 DigitalIn sw_top;
chinetion 1:0b8836a7cd96 12 DigitalIn sw_bot;
chinetion 0:57b3f673b395 13 };
chinetion 1:0b8836a7cd96 14 MOTOR::MOTOR(PinName pin_a,PinName pin_b):a(pin_a),b(pin_b),sw_top(D4),sw_bot(D5){
chinetion 1:0b8836a7cd96 15 stop();
chinetion 1:0b8836a7cd96 16 }
chinetion 1:0b8836a7cd96 17 void MOTOR::read(){
chinetion 1:0b8836a7cd96 18 printf("%d\n",sw_top.read());
chinetion 0:57b3f673b395 19 }
chinetion 0:57b3f673b395 20 void MOTOR::forward(){
chinetion 1:0b8836a7cd96 21 while(!sw_top.read()){
chinetion 1:0b8836a7cd96 22 a=0;b=1;
chinetion 1:0b8836a7cd96 23 }
chinetion 1:0b8836a7cd96 24 stop();
chinetion 0:57b3f673b395 25 }
chinetion 0:57b3f673b395 26 void MOTOR::backward(){
chinetion 1:0b8836a7cd96 27 while(!sw_bot.read()){
chinetion 1:0b8836a7cd96 28 a=1;b=0;
chinetion 1:0b8836a7cd96 29 }
chinetion 1:0b8836a7cd96 30 stop();
chinetion 0:57b3f673b395 31 }
chinetion 0:57b3f673b395 32 void MOTOR::stop(){
chinetion 0:57b3f673b395 33 a=1;
chinetion 0:57b3f673b395 34 b=1;
chinetion 0:57b3f673b395 35 }