![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Just trying to read values into Terraterm
Diff: main.cpp
- Revision:
- 1:68153aa41971
- Parent:
- 0:a4ee67431356
- Child:
- 2:5c83943df240
diff -r a4ee67431356 -r 68153aa41971 main.cpp --- a/main.cpp Thu Apr 23 23:49:13 2015 +0000 +++ b/main.cpp Fri Apr 24 01:00:24 2015 +0000 @@ -1,11 +1,38 @@ #include "mbed.h" #include "Motor.h" AnalogIn sonic(p15); -float data; +Motor R(p24, p25, p26); +Motor L(p21, p22, p23); -int main() { +float data; +float sum; +float average; +float desired; +float erro; +int p; +int count; +int main() +{ while(1) { - data=bed.read(); - printf("%f \n",data); + + for(count=0; count<=100; count++) { + data=sonic.read(); + sum=0; + for(p=0; p<=50; p++) { + sum =sum+data; + } + average= sum/50; + printf("%f \n",average); + desired=.012205; + erro=desired-average; + + if(erro<.001) { + L.speed(0.2); + R.speed(0.2); + } + + + wait(.1); + + } } -}