works

Dependencies:   SRF05 mbed

Fork of SRF05_HelloWorld by Simon Ford

Committer:
Aidan2521
Date:
Tue Nov 29 19:32:11 2016 +0000
Revision:
4:87d6d45092c5
Parent:
3:1b2fffffb566
Child:
5:df7cdf275ec9
Not working currently

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"
Aidan2521 4:87d6d45092c5 4 #include "Adafruit_GFX.h"
Aidan2521 4:87d6d45092c5 5 #include "Adafruit_SSD1306.h"
simon 0:d87132986e8f 6 #include "SRF05.h"
simon 0:d87132986e8f 7
Aidan2521 4:87d6d45092c5 8 SPIPreInit Gspi(p5, p6, p7);
Aidan2521 4:87d6d45092c5 9 SPI spi(p5, p6, p7);
Aidan2521 4:87d6d45092c5 10 Adafruit_SSD1306_Spi ssd(spi, p5, p6, p7);
darcy11025 1:612f5d9de345 11 SRF05 srf(p9, p10);
simon 0:d87132986e8f 12
simon 0:d87132986e8f 13 int main() {
Aidan2521 2:f9045153af1e 14 float curval;
Aidan2521 2:f9045153af1e 15 float percentage;
Aidan2521 2:f9045153af1e 16 float tankfull = 5;
Aidan2521 2:f9045153af1e 17 float tankempty = 35;
Aidan2521 2:f9045153af1e 18 float range = tankempty-tankfull; // 100-(value-5)/range*100
simon 0:d87132986e8f 19 while(1) {
Aidan2521 2:f9045153af1e 20 curval = srf.read();
Aidan2521 2:f9045153af1e 21 percentage = 100-((curval-5)/range)*100;
Aidan2521 4:87d6d45092c5 22 printf ("P,V: %.0f (%.0f)\n\r", percentage, curval);
Aidan2521 4:87d6d45092c5 23 ssd.printf ("P,V: %.0f (%.0f)\n\r", percentage, curval);
simon 0:d87132986e8f 24 wait(0.2);
simon 0:d87132986e8f 25 }
simon 0:d87132986e8f 26 }