works

Dependencies:   SRF05 mbed

Fork of SRF05_HelloWorld by Simon Ford

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // Simple program to read the distance from an SRF05 using the SRF05 library
00002 
00003 #include "mbed.h"
00004 #include "SRF05.h"
00005 
00006 SRF05 srf(p9, p10);
00007  
00008 int main() { 
00009     float curval;
00010     float percentage;
00011     float tankfull = 10;
00012     float tankempty = 60;
00013     float warning = 10; //percentage
00014     float range = tankempty-tankfull; // 100-(value-5)/range*100
00015      while(1) { 
00016          curval = srf.read();
00017          percentage = 100-(((curval-tankfull)/range)*100);
00018          printf ("Percentage Remaining: %.0f (%.0f)\n\r", percentage, curval);
00019          if (percentage < warning){
00020              printf ("WARNING: Water Level Below 10% \n\r");
00021              }             
00022          wait(1); 
00023      } 
00024  }