Ling Ye
/
Serial
bbb
Revision 1:a95f56d5e053, committed 2016-11-02
- Comitter:
- lingye96
- Date:
- Wed Nov 02 19:44:07 2016 +0000
- Parent:
- 0:48d48099e20c
- Commit message:
- asdf
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 48d48099e20c -r a95f56d5e053 main.cpp --- a/main.cpp Tue Nov 01 03:54:17 2016 +0000 +++ b/main.cpp Wed Nov 02 19:44:07 2016 +0000 @@ -2,44 +2,40 @@ #include "m3pi.h" m3pi m3pi; -Serial pc(USBTX,USCRX); +Serial pc(USBTX, USBRX); int main() { - m3pi.locate(0,1); - m3pi.printf("Serial Control"); - pc.printf("Press 'WASD' to control the m3pi\n"); - - while (1) + pc.printf("Press and control the m3pi\n"); + while(1) { - wait (2.0); - char input = pc.getc(); - if(input=='w') + char c = pc.getc(); + if(c =='w') { m3pi.forward(0.5); // Forward half speed - wait (0.5); // wait half a second - } - else if (input=='a') + wait (0.25); // wait half a second + m3pi.stop(); + } + if (c =='a') { m3pi.left(0.5); // Turn left at half speed - wait (0.5); // wait half a second - } - else if (input=='s') - } - m3pi.backward(0.5);// Backward at half speed - wait (0.5); // wait half a second - } - else if (input=='d') + wait (0.25); // wait half a second + m3pi.stop(); + } + if (c =='s') { - m3pi.right(0.5); // Turn right at half speed - wait (0.5); // wait half a second - } - else + m3pi.backward(0.5); // Turn left at half speed + wait (0.25); // wait half a second + m3pi.stop(); + } + if (c =='d') { - pc.printf("Try again and press 'WASD' to control the m3pi\n"); - } - m3pi.printf("Complete"); + m3pi.right(0.5); // Turn left at half speed + wait (0.25); // wait half a second + m3pi.stop(); + } + wait (2.0); + } - }