EES Stephen Perse Sixth Form
/
SRF05_HelloWorld
works
Fork of SRF05_HelloWorld by
main.cpp
- Committer:
- Aidan2521
- Date:
- 2016-11-29
- Revision:
- 4:87d6d45092c5
- Parent:
- 3:1b2fffffb566
- Child:
- 5:df7cdf275ec9
File content as of revision 4:87d6d45092c5:
// Simple program to read the distance from an SRF05 using the SRF05 library #include "mbed.h" #include "Adafruit_GFX.h" #include "Adafruit_SSD1306.h" #include "SRF05.h" SPIPreInit Gspi(p5, p6, p7); SPI spi(p5, p6, p7); Adafruit_SSD1306_Spi ssd(spi, p5, p6, p7); 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) { curval = srf.read(); percentage = 100-((curval-5)/range)*100; printf ("P,V: %.0f (%.0f)\n\r", percentage, curval); ssd.printf ("P,V: %.0f (%.0f)\n\r", percentage, curval); wait(0.2); } }