![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Just trying to read values into Terraterm
main.cpp@1:68153aa41971, 2015-04-24 (annotated)
- Committer:
- jkangwi
- Date:
- Fri Apr 24 01:00:24 2015 +0000
- Revision:
- 1:68153aa41971
- Parent:
- 0:a4ee67431356
- Child:
- 2:5c83943df240
Ultrasonic
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 | 1:68153aa41971 | 10 | float desired; |
jkangwi | 1:68153aa41971 | 11 | float erro; |
jkangwi | 1:68153aa41971 | 12 | int p; |
jkangwi | 1:68153aa41971 | 13 | int count; |
jkangwi | 1:68153aa41971 | 14 | int main() |
jkangwi | 1:68153aa41971 | 15 | { |
jkangwi | 0:a4ee67431356 | 16 | while(1) { |
jkangwi | 1:68153aa41971 | 17 | |
jkangwi | 1:68153aa41971 | 18 | for(count=0; count<=100; count++) { |
jkangwi | 1:68153aa41971 | 19 | data=sonic.read(); |
jkangwi | 1:68153aa41971 | 20 | sum=0; |
jkangwi | 1:68153aa41971 | 21 | for(p=0; p<=50; p++) { |
jkangwi | 1:68153aa41971 | 22 | sum =sum+data; |
jkangwi | 1:68153aa41971 | 23 | } |
jkangwi | 1:68153aa41971 | 24 | average= sum/50; |
jkangwi | 1:68153aa41971 | 25 | printf("%f \n",average); |
jkangwi | 1:68153aa41971 | 26 | desired=.012205; |
jkangwi | 1:68153aa41971 | 27 | erro=desired-average; |
jkangwi | 1:68153aa41971 | 28 | |
jkangwi | 1:68153aa41971 | 29 | if(erro<.001) { |
jkangwi | 1:68153aa41971 | 30 | L.speed(0.2); |
jkangwi | 1:68153aa41971 | 31 | R.speed(0.2); |
jkangwi | 1:68153aa41971 | 32 | } |
jkangwi | 1:68153aa41971 | 33 | |
jkangwi | 1:68153aa41971 | 34 | |
jkangwi | 1:68153aa41971 | 35 | wait(.1); |
jkangwi | 1:68153aa41971 | 36 | |
jkangwi | 1:68153aa41971 | 37 | } |
jkangwi | 0:a4ee67431356 | 38 | } |