![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Just trying to read values into Terraterm
main.cpp@3:9aab8f5b6508, 2015-04-27 (annotated)
- Committer:
- jkangwi
- Date:
- Mon Apr 27 01:12:28 2015 +0000
- Revision:
- 3:9aab8f5b6508
- Parent:
- 2:5c83943df240
Subsytem only
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jkangwi | 0:a4ee67431356 | 1 | #include "mbed.h" |
jkangwi | 0:a4ee67431356 | 2 | #include "Motor.h" |
jkangwi | 0:a4ee67431356 | 3 | AnalogIn sonic(p15); |
jkangwi | 1:68153aa41971 | 4 | Motor R(p24, p25, p26); |
jkangwi | 1:68153aa41971 | 5 | Motor L(p21, p22, p23); |
jkangwi | 0:a4ee67431356 | 6 | |
jkangwi | 1:68153aa41971 | 7 | float data; |
jkangwi | 1:68153aa41971 | 8 | float sum; |
jkangwi | 1:68153aa41971 | 9 | float average; |
jkangwi | 2:5c83943df240 | 10 | |
jkangwi | 1:68153aa41971 | 11 | int p; |
jkangwi | 1:68153aa41971 | 12 | int count; |
jkangwi | 1:68153aa41971 | 13 | int main() |
jkangwi | 1:68153aa41971 | 14 | { |
jkangwi | 0:a4ee67431356 | 15 | while(1) { |
jkangwi | 2:5c83943df240 | 16 | data=sonic.read(); |
jkangwi | 2:5c83943df240 | 17 | sum=0; |
jkangwi | 2:5c83943df240 | 18 | for(p=0; p<=50; p++) { |
jkangwi | 2:5c83943df240 | 19 | sum =sum+data; |
jkangwi | 2:5c83943df240 | 20 | } |
jkangwi | 2:5c83943df240 | 21 | average= sum/50; |
jkangwi | 2:5c83943df240 | 22 | printf("%f \n",average); |
jkangwi | 2:5c83943df240 | 23 | while(average>.014198) { |
jkangwi | 1:68153aa41971 | 24 | data=sonic.read(); |
jkangwi | 1:68153aa41971 | 25 | sum=0; |
jkangwi | 1:68153aa41971 | 26 | for(p=0; p<=50; p++) { |
jkangwi | 1:68153aa41971 | 27 | sum =sum+data; |
jkangwi | 1:68153aa41971 | 28 | } |
jkangwi | 1:68153aa41971 | 29 | average= sum/50; |
jkangwi | 3:9aab8f5b6508 | 30 | L.speed(0.35); |
jkangwi | 3:9aab8f5b6508 | 31 | R.speed(-0.35); |
jkangwi | 1:68153aa41971 | 32 | printf("%f \n",average); |
jkangwi | 1:68153aa41971 | 33 | |
jkangwi | 1:68153aa41971 | 34 | } |
jkangwi | 2:5c83943df240 | 35 | L.speed(0.0); |
jkangwi | 2:5c83943df240 | 36 | R.speed(0.0); |
jkangwi | 2:5c83943df240 | 37 | wait(.01); |
jkangwi | 2:5c83943df240 | 38 | |
jkangwi | 0:a4ee67431356 | 39 | } |
jkangwi | 2:5c83943df240 | 40 | } |