bbb

Dependencies:   m3pi mbed

Committer:
lingye96
Date:
Tue Nov 01 03:54:17 2016 +0000
Revision:
0:48d48099e20c
Child:
1:a95f56d5e053
Serial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lingye96 0:48d48099e20c 1 #include "mbed.h"
lingye96 0:48d48099e20c 2 #include "m3pi.h"
lingye96 0:48d48099e20c 3
lingye96 0:48d48099e20c 4 m3pi m3pi;
lingye96 0:48d48099e20c 5 Serial pc(USBTX,USCRX);
lingye96 0:48d48099e20c 6
lingye96 0:48d48099e20c 7 int main() {
lingye96 0:48d48099e20c 8
lingye96 0:48d48099e20c 9
lingye96 0:48d48099e20c 10 m3pi.locate(0,1);
lingye96 0:48d48099e20c 11 m3pi.printf("Serial Control");
lingye96 0:48d48099e20c 12 pc.printf("Press 'WASD' to control the m3pi\n");
lingye96 0:48d48099e20c 13
lingye96 0:48d48099e20c 14 while (1)
lingye96 0:48d48099e20c 15 {
lingye96 0:48d48099e20c 16 wait (2.0);
lingye96 0:48d48099e20c 17 char input = pc.getc();
lingye96 0:48d48099e20c 18 if(input=='w')
lingye96 0:48d48099e20c 19 {
lingye96 0:48d48099e20c 20 m3pi.forward(0.5); // Forward half speed
lingye96 0:48d48099e20c 21 wait (0.5); // wait half a second
lingye96 0:48d48099e20c 22 }
lingye96 0:48d48099e20c 23 else if (input=='a')
lingye96 0:48d48099e20c 24 {
lingye96 0:48d48099e20c 25 m3pi.left(0.5); // Turn left at half speed
lingye96 0:48d48099e20c 26 wait (0.5); // wait half a second
lingye96 0:48d48099e20c 27 }
lingye96 0:48d48099e20c 28 else if (input=='s')
lingye96 0:48d48099e20c 29 }
lingye96 0:48d48099e20c 30 m3pi.backward(0.5);// Backward at half speed
lingye96 0:48d48099e20c 31 wait (0.5); // wait half a second
lingye96 0:48d48099e20c 32 }
lingye96 0:48d48099e20c 33 else if (input=='d')
lingye96 0:48d48099e20c 34 {
lingye96 0:48d48099e20c 35 m3pi.right(0.5); // Turn right at half speed
lingye96 0:48d48099e20c 36 wait (0.5); // wait half a second
lingye96 0:48d48099e20c 37 }
lingye96 0:48d48099e20c 38 else
lingye96 0:48d48099e20c 39 {
lingye96 0:48d48099e20c 40 pc.printf("Try again and press 'WASD' to control the m3pi\n");
lingye96 0:48d48099e20c 41 }
lingye96 0:48d48099e20c 42 m3pi.printf("Complete");
lingye96 0:48d48099e20c 43 }
lingye96 0:48d48099e20c 44
lingye96 0:48d48099e20c 45 }