EES Stephen Perse Sixth Form
/
SRF05_HelloWorld
works
Fork of SRF05_HelloWorld by
Diff: main.cpp
- Revision:
- 2:f9045153af1e
- Parent:
- 1:612f5d9de345
- Child:
- 3:1b2fffffb566
diff -r 612f5d9de345 -r f9045153af1e main.cpp --- a/main.cpp Tue Nov 29 15:48:54 2016 +0000 +++ b/main.cpp Tue Nov 29 16:12:11 2016 +0000 @@ -6,8 +6,15 @@ SRF05 srf(p9, p10); int main() { + float curval; + float percentage; + float tankfull = 5; + float tankempty = 35; + float range = tankempty-tankfull; // 100-(value-5)/range*100 while(1) { - printf("Distance = %.1f\n\r", srf.read()); + curval = srf.read(); + percentage = 100-((curval-5)/range)*100; + printf ("Percentage Remaining: %.0f", percentage); wait(0.2); } } \ No newline at end of file