shashidhar dastari
/
robot_control
main.cpp@0:6709e55d3cdd, 2018-03-20 (annotated)
- Committer:
- kirathekiller
- Date:
- Tue Mar 20 04:30:39 2018 +0000
- Revision:
- 0:6709e55d3cdd
Remote Controlled Robot
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kirathekiller | 0:6709e55d3cdd | 1 | #include "mbed.h" |
kirathekiller | 0:6709e55d3cdd | 2 | //#include <stdio.h> |
kirathekiller | 0:6709e55d3cdd | 3 | //#include <string.h> |
kirathekiller | 0:6709e55d3cdd | 4 | |
kirathekiller | 0:6709e55d3cdd | 5 | |
kirathekiller | 0:6709e55d3cdd | 6 | |
kirathekiller | 0:6709e55d3cdd | 7 | |
kirathekiller | 0:6709e55d3cdd | 8 | |
kirathekiller | 0:6709e55d3cdd | 9 | DigitalOut m1f(PTC2); |
kirathekiller | 0:6709e55d3cdd | 10 | DigitalOut m1r(PTC3); |
kirathekiller | 0:6709e55d3cdd | 11 | DigitalOut m2f(PTC4); |
kirathekiller | 0:6709e55d3cdd | 12 | DigitalOut m2r(PTC12); |
kirathekiller | 0:6709e55d3cdd | 13 | |
kirathekiller | 0:6709e55d3cdd | 14 | Serial pc(USBTX, USBRX); |
kirathekiller | 0:6709e55d3cdd | 15 | Serial blue(PTC15, PTC14); |
kirathekiller | 0:6709e55d3cdd | 16 | char c=0; |
kirathekiller | 0:6709e55d3cdd | 17 | |
kirathekiller | 0:6709e55d3cdd | 18 | int main() |
kirathekiller | 0:6709e55d3cdd | 19 | { |
kirathekiller | 0:6709e55d3cdd | 20 | while (true) { |
kirathekiller | 0:6709e55d3cdd | 21 | |
kirathekiller | 0:6709e55d3cdd | 22 | if(blue.readable()>0) |
kirathekiller | 0:6709e55d3cdd | 23 | { |
kirathekiller | 0:6709e55d3cdd | 24 | c=blue.getc(); |
kirathekiller | 0:6709e55d3cdd | 25 | } |
kirathekiller | 0:6709e55d3cdd | 26 | if(c=='F')//forward |
kirathekiller | 0:6709e55d3cdd | 27 | { |
kirathekiller | 0:6709e55d3cdd | 28 | m1f = 1; |
kirathekiller | 0:6709e55d3cdd | 29 | m1r = 0; |
kirathekiller | 0:6709e55d3cdd | 30 | m2f = 1; |
kirathekiller | 0:6709e55d3cdd | 31 | m2r = 0; |
kirathekiller | 0:6709e55d3cdd | 32 | } |
kirathekiller | 0:6709e55d3cdd | 33 | |
kirathekiller | 0:6709e55d3cdd | 34 | else if(c=='B') //backward |
kirathekiller | 0:6709e55d3cdd | 35 | //wait(0.2f); |
kirathekiller | 0:6709e55d3cdd | 36 | { |
kirathekiller | 0:6709e55d3cdd | 37 | m1f = 0; |
kirathekiller | 0:6709e55d3cdd | 38 | m1r = 1; |
kirathekiller | 0:6709e55d3cdd | 39 | m2f = 0; |
kirathekiller | 0:6709e55d3cdd | 40 | m2r = 1; |
kirathekiller | 0:6709e55d3cdd | 41 | } |
kirathekiller | 0:6709e55d3cdd | 42 | else if(c=='L') //left |
kirathekiller | 0:6709e55d3cdd | 43 | { |
kirathekiller | 0:6709e55d3cdd | 44 | m1f = 1; |
kirathekiller | 0:6709e55d3cdd | 45 | m1r = 0; |
kirathekiller | 0:6709e55d3cdd | 46 | m2f = 0; |
kirathekiller | 0:6709e55d3cdd | 47 | m2r = 0; |
kirathekiller | 0:6709e55d3cdd | 48 | } |
kirathekiller | 0:6709e55d3cdd | 49 | else if(c=='R') //right |
kirathekiller | 0:6709e55d3cdd | 50 | { |
kirathekiller | 0:6709e55d3cdd | 51 | m1f = 0; |
kirathekiller | 0:6709e55d3cdd | 52 | m1r = 0; |
kirathekiller | 0:6709e55d3cdd | 53 | m2f = 1; |
kirathekiller | 0:6709e55d3cdd | 54 | m2r = 0; |
kirathekiller | 0:6709e55d3cdd | 55 | } |
kirathekiller | 0:6709e55d3cdd | 56 | else if(c=='S') //stop |
kirathekiller | 0:6709e55d3cdd | 57 | { |
kirathekiller | 0:6709e55d3cdd | 58 | m1f = 0; |
kirathekiller | 0:6709e55d3cdd | 59 | m1r = 0; |
kirathekiller | 0:6709e55d3cdd | 60 | m2f = 0; |
kirathekiller | 0:6709e55d3cdd | 61 | m2r = 0; |
kirathekiller | 0:6709e55d3cdd | 62 | } |
kirathekiller | 0:6709e55d3cdd | 63 | |
kirathekiller | 0:6709e55d3cdd | 64 | } |
kirathekiller | 0:6709e55d3cdd | 65 | } |