EES Stephen Perse Sixth Form
/
SRF05_HelloWorld
works
Fork of SRF05_HelloWorld by
main.cpp@6:fae63ea5ba75, 2016-12-06 (annotated)
- Committer:
- Aidan2521
- Date:
- Tue Dec 06 16:19:08 2016 +0000
- Revision:
- 6:fae63ea5ba75
- Parent:
- 5:df7cdf275ec9
- Child:
- 7:974ba1b166ad
Works 6/12/16
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 | 6:fae63ea5ba75 | 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 | } |