works

Dependencies:   SRF05 mbed

Fork of SRF05_HelloWorld by Simon Ford

Committer:
Aidan2521
Date:
Tue Dec 06 16:41:06 2016 +0000
Revision:
7:974ba1b166ad
Parent:
6:fae63ea5ba75
Displays warning message when below 10%; changed tank values

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:d87132986e8f 1 // Simple program to read the distance from an SRF05 using the SRF05 library
simon 0:d87132986e8f 2
simon 0:d87132986e8f 3 #include "mbed.h"
simon 0:d87132986e8f 4 #include "SRF05.h"
simon 0:d87132986e8f 5
darcy11025 1:612f5d9de345 6 SRF05 srf(p9, p10);
simon 0:d87132986e8f 7
simon 0:d87132986e8f 8 int main() {
Aidan2521 2:f9045153af1e 9 float curval;
Aidan2521 2:f9045153af1e 10 float percentage;
Aidan2521 7:974ba1b166ad 11 float tankfull = 10;
Aidan2521 7:974ba1b166ad 12 float tankempty = 60;
Aidan2521 7:974ba1b166ad 13 float warning = 10; //percentage
Aidan2521 2:f9045153af1e 14 float range = tankempty-tankfull; // 100-(value-5)/range*100
simon 0:d87132986e8f 15 while(1) {
Aidan2521 2:f9045153af1e 16 curval = srf.read();
Aidan2521 7:974ba1b166ad 17 percentage = 100-(((curval-tankfull)/range)*100);
Aidan2521 7:974ba1b166ad 18 printf ("Percentage Remaining: %.0f (%.0f)\n\r", percentage, curval);
Aidan2521 7:974ba1b166ad 19 if (percentage < warning){
Aidan2521 7:974ba1b166ad 20 printf ("WARNING: Water Level Below 10% \n\r");
Aidan2521 7:974ba1b166ad 21 }
Aidan2521 7:974ba1b166ad 22 wait(1);
simon 0:d87132986e8f 23 }
simon 0:d87132986e8f 24 }