Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: DISCO-F746NG_LCDTS_demo Srf08Test
You are viewing an older revision! See the latest version
Homepage
Tips¶
Don't forget to add the pullup resistors from 5v to SDA and SCL!
Example program¶
#include "mbed.h"
#include "SRF08.h"
Serial PC(USBTX, USBRX); //Debug port to PC
SRF08 rangeMod1(p28, p27, 0xE4); //SRF08 ranging module 1
SRF08 rangeMod2(p28, p27, 0xE2); //SRF08 ranging module 2
int main() {
PC.printf("Start ranging test \n");
rangeMod1.setAddress(0xE4); //Factory default is 0xE0
while(1) {
rangeMod1.startRanging();
while (!rangeMod1.rangingFinished() ) wait(0.01);
int range1 = rangeMod1.getRange();
int light1 = rangeMod1.getLightIntensity();
rangeMod2.startRanging();
while (!rangeMod2.rangingFinished() ) wait(0.01);
int range2 = rangeMod2.getRange();
PC.printf(" Range_1: %i", range1);
PC.printf(" Range_2: %i", range2);
PC.printf(" Light_1: %i", light1);
PC.printf("\n");
}
}