works

Dependencies:   SRF05 mbed

Fork of SRF05_HelloWorld by Simon Ford

Committer:
Aidan2521
Date:
Tue Dec 06 14:44:31 2016 +0000
Revision:
5:df7cdf275ec9
Parent:
4:87d6d45092c5
Child:
6:fae63ea5ba75
testing for working

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 2:f9045153af1e 11 float tankfull = 5;
Aidan2521 2:f9045153af1e 12 float tankempty = 35;
Aidan2521 2:f9045153af1e 13 float range = tankempty-tankfull; // 100-(value-5)/range*100
simon 0:d87132986e8f 14 while(1) {
Aidan2521 2:f9045153af1e 15 curval = srf.read();
Aidan2521 2:f9045153af1e 16 percentage = 100-((curval-5)/range)*100;
Aidan2521 5:df7cdf275ec9 17 printf ("Percentage Remaining: %.0f (%.0f)\n\r", percentage, curval);
simon 0:d87132986e8f 18 wait(0.2);
simon 0:d87132986e8f 19 }
simon 0:d87132986e8f 20 }