![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
stop cart
Dependencies: mbed ContinuousServo
main.cpp
- Committer:
- m211002
- Date:
- 2019-04-17
- Revision:
- 0:9952fdc226ac
- Child:
- 1:cf9ba941d8c2
File content as of revision 0:9952fdc226ac:
#include "mbed.h" Serial pc(USBTX,USBRX); //sonar sensor AnalogIn sonar(p19); //range sensor 9.8mV/inch int main() { while(1) { float distance,x; int num_iterations,i; pc.scanf("%d",&num_iterations);//reads in values from the Matlab for(i=1; i<=num_iterations; i++) { //will go until it meets the number of iterations x = sonar.read();//takes the sensor redings and converts them to x distance=x; //if distance is == to desired distance than stop left and right wheels stopvalue = .033 if(x>stopvalue){ left.speed(.5); right.speed(.5); }else{ left.stop(); right.stop(); } wait(0.1); pc.printf("%f\n",x);//mbed send out float values for Matlab } } }