motor

Dependencies:   VNH5019 mbed

Committer:
s1210160
Date:
Fri Jul 22 07:08:05 2016 +0000
Revision:
2:b7676b0b020e
Parent:
1:6ad72ace0fec
2016/07/22

Who changed what in which revision?

UserRevisionLine numberNew contents of line
s1210160 0:974de11b1491 1 #include "mbed.h"
s1210160 0:974de11b1491 2 #include "VNH5019.h"
s1210160 0:974de11b1491 3
s1210160 0:974de11b1491 4 VNH5019 motorShield(p23,p22,p25,p21,p24,p26);
s1210160 0:974de11b1491 5 Serial pc(USBTX, USBRX);
s1210160 0:974de11b1491 6 Serial xbee(p13, p14);
s1210160 0:974de11b1491 7
s1210160 0:974de11b1491 8 int main()
s1210160 0:974de11b1491 9 {
s1210160 1:6ad72ace0fec 10 xbee.baud(57600);
s1210160 1:6ad72ace0fec 11 pc.baud(57600);
s1210160 0:974de11b1491 12
s1210160 0:974de11b1491 13 char c;
s1210160 0:974de11b1491 14
s1210160 0:974de11b1491 15 while(true) {
s1210160 0:974de11b1491 16 c = xbee.getc();
s1210160 0:974de11b1491 17
s1210160 1:6ad72ace0fec 18 // front
s1210160 0:974de11b1491 19 if(c == 'f') {
s1210160 1:6ad72ace0fec 20 xbee.printf("f\n");
s1210160 1:6ad72ace0fec 21 motorShield.changeSpeed(1, 64, 1, 64);
s1210160 0:974de11b1491 22 }
s1210160 0:974de11b1491 23
s1210160 1:6ad72ace0fec 24 // back
s1210160 0:974de11b1491 25 if(c == 'b'){
s1210160 1:6ad72ace0fec 26 xbee.printf("b\n");
s1210160 1:6ad72ace0fec 27 motorShield.changeSpeed(2, 64, 2, 64);
s1210160 0:974de11b1491 28 }
s1210160 0:974de11b1491 29
s1210160 1:6ad72ace0fec 30 // left
s1210160 0:974de11b1491 31 if(c == 'l'){
s1210160 1:6ad72ace0fec 32 xbee.printf("l\n");
s1210160 2:b7676b0b020e 33 motorShield.changeSpeed(1, 32, 1, 64);
s1210160 0:974de11b1491 34 }
s1210160 0:974de11b1491 35
s1210160 1:6ad72ace0fec 36 // right
s1210160 0:974de11b1491 37 if(c == 'r') {
s1210160 1:6ad72ace0fec 38 xbee.printf("r\n");
s1210160 2:b7676b0b020e 39 motorShield.changeSpeed(1, 64, 1, 32);
s1210160 0:974de11b1491 40 }
s1210160 0:974de11b1491 41
s1210160 1:6ad72ace0fec 42 // stop
s1210160 0:974de11b1491 43 if(c == 's') {
s1210160 1:6ad72ace0fec 44 xbee.printf("s\n");
s1210160 1:6ad72ace0fec 45 motorShield.changeSpeed(0, 64, 0, 64);
s1210160 0:974de11b1491 46 }
s1210160 0:974de11b1491 47 }
s1210160 0:974de11b1491 48 return 0;
s1210160 0:974de11b1491 49 }