Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- 1050186
- Date:
- 2016-04-20
- Revision:
- 1:da6118c4da1f
- Parent:
- 0:f8c34fd5e223
File content as of revision 1:da6118c4da1f:
#include "mbed.h"
AnalogIn ain(A0);
DigitalOut led1(LED_RED);
Ticker flipper;
int f_sen = 0;
void flip() {
float tmp1 = 0;
float tmp2 = 0;
float data;
float distance;
tmp1 = ain;
tmp2 = ain;
data = (tmp1 + tmp2) / 2.0f;
if ((0.121 <= data) && (data <= 0.970)) {
distance = 26.663 * pow((data * 3.3),-1.25);
printf("Distance : %4.3f[cm]\n",distance);
f_sen = 1;
} else {
printf("Distance : ------[cm]\n");
f_sen = 0;
}
}
int main() {
printf("Sensor start!\n");
flipper.attach_us(&flip, 500000);//500ms
while(1) {
if(f_sen == 1){
led1 = 1;
} else {
led1 = 0;
}
wait(0.5);
}
}