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.
Dependencies: mbed Servo ros_lib_kinetic
Diff: main.cpp
- Revision:
- 0:6021ec1b1449
- Child:
- 1:9bc7f95c3c7d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Oct 22 11:56:57 2019 +0000 @@ -0,0 +1,68 @@ +/*-------------------------------------------------------------------------------- +Filename: main.cpp +Description: Main program loop +--------------------------------------------------------------------------------*/ +#include "mbed.h" +#include "TOF.h" + +Serial pc(SERIAL_TX, SERIAL_RX, 9600); // set-up serial to pc +cAdafruit_VL6180X VL6180X; //Define TOF sensor class + +DigitalOut CS1(PC_8); +DigitalOut CS2(PC_9); + +int main() +{ + int range1, range2; + + CS1 = 0; + CS2 = 0; + wait(0.01); + + CS1 = 1; + wait(0.01); + VL6180X.Setup(DEFAULT_ADDRESS, ADDRESS1); + VL6180X.Init(ADDRESS1); + VL6180X.Start_Range(ADDRESS1); + + CS2 = 1; + wait(0.01); + VL6180X.Setup(DEFAULT_ADDRESS, ADDRESS2); + VL6180X.Init(ADDRESS2); + VL6180X.Start_Range(ADDRESS2); + + + + pc.printf("INITIALISED\n\r"); + + while(1) { + + // poll the VL6180X till new sample ready + VL6180X.Poll_Range(ADDRESS1); + pc.printf("POLL1"); + + // read range result + range1 = VL6180X.Read_Range(ADDRESS1); + pc.printf("READ RANGE1"); + + // clear the interrupt on VL6180X + VL6180X.Clear_Interrupts(ADDRESS1); + pc.printf("READRANGE1"); + + // poll the VL6180X till new sample ready + VL6180X.Poll_Range(ADDRESS2); + pc.printf("POLL2"); + + // read range result + range2 = VL6180X.Read_Range(ADDRESS2); + pc.printf("READ RANGE2"); + + // clear the interrupt on VL6180X + VL6180X.Clear_Interrupts(ADDRESS2); + pc.printf("READRANGE2"); + + // send range to pc by serial + pc.printf("SENSOR1:%d SENSOR2: %d\r\n", range1, range2); + wait(0.1); + } +} \ No newline at end of file