EES Stephen Perse Sixth Form
/
SRF05_HelloWorld
works
Fork of SRF05_HelloWorld by
main.cpp@2:f9045153af1e, 2016-11-29 (annotated)
- Committer:
- Aidan2521
- Date:
- Tue Nov 29 16:12:11 2016 +0000
- Revision:
- 2:f9045153af1e
- Parent:
- 1:612f5d9de345
- Child:
- 3:1b2fffffb566
Added method for displaying percentage rather range
Who changed what in which revision?
User | Revision | Line number | New 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 | 2:f9045153af1e | 17 | printf ("Percentage Remaining: %.0f", percentage); |
simon | 0:d87132986e8f | 18 | wait(0.2); |
simon | 0:d87132986e8f | 19 | } |
simon | 0:d87132986e8f | 20 | } |