Tadao Iida / Mbed 2 deprecated e-ruler

Dependencies:   TextLCD mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "TextLCD.h"
00003 
00004 AnalogIn in(p20);
00005 AnalogOut out(p18) ;
00006 TextLCD lcd(p24, p26, p27, p28, p29, p30) ;
00007 Ticker input;
00008 float now, old = 0.0 ;
00009 
00010 void run(void);
00011 int main() {
00012     input.attach(&run,0.5);  
00013     while(1) {
00014 
00015     }
00016 }
00017 
00018 void run(void)
00019 {
00020     float data;
00021     old = now ;
00022     now = in ;
00023     
00024     data = (now +old)/2.0 ;
00025     lcd.locate(0,0) ;
00026     if (0.121 <= data && data <= 0.970){
00027         float range = 25.33 * pow((data*3.3),-1.21);
00028         lcd.printf("Range: %4.1f[cm]",range) ;
00029         out = 0.5;
00030     }else{
00031        lcd.printf("Range: ----[cm]");
00032        out = 1.0;
00033     }
00034 }