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.
Homepage
#include "mbed.h"
#include "MjGP2Y0E03.h"
using namespace matsujirushi;
Serial pc(USBTX, USBRX);
I2C i2c(dp5, dp27);
MjGP2Y0E03 distanceSensor(&i2c, 0x80);
int main()
{
pc.baud(115200);
i2c.frequency(400000);
for(;;)
{
uint16_t distance = distanceSensor.getDistance();
pc.printf("%4d [", distance);
int i;
for (i = 0; i < distance / 50; i++)
{
pc.putc('*');
}
for (; i < 4096 / 50; i++)
{
pc.putc(' ');
}
pc.puts("]\r\n");
wait_ms(50);
}
}