Robot team project
Dependencies: QEI Motordriver ros_lib_melodic
Diff: main.cpp
- Revision:
- 0:57855aafa907
- Child:
- 1:d5adc483bce0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Oct 22 09:12:03 2019 +0000 @@ -0,0 +1,84 @@ +#include "mbed.h" +#include "Sensor.h" + +// Set up serial to pc +Serial pc(SERIAL_TX, SERIAL_RX); + +// Set up I²C on the STM32 NUCLEO-401RE +#define addr1 (0x29) +#define addr2 (0x2A) +#define addr3 (0x2B) +#define addr4 (0x2C) + +//Macro for addresses +// I²C address of VL6180 shifted by 1 bit +//(0x29 << 1) so the R/W command can be added +#define ADDR1 (addr1<<1) +#define ADDR2 (addr2<<1) +#define ADDR3 (addr3<<1) +#define ADDR4 (addr4<<1) + +int main() { + int range1; + int range2=0; + int range3=0; + int range4=0; + + // Create and init sensor 1 + Sensor sensor1(ADDR1, I2C_SDA, I2C_SCL, PC_9); + + /* + Sensor sensor2(ADDR2, I2C_SDA, I2C_SCL, PC_11); + Sensor sensor3(ADDR3, I2C_SDA, I2C_SCL, PD_2); + Sensor sensor4(ADDR4, I2C_SDA, I2C_SCL, PG_3); + */ + + /* + SHDN_1 = 0; + SHDN_3 = 0; + SHDN_2 = 0; + SHDN_4 = 0; + wait_ms(0.5); + + SHDN_1 = 0; + SHDN_2 = 1; + SHDN_3 = 0; + SHDN_4 = 0; + */ + + + /* + // load settings onto VL6180X sensors + VL6180_Init(ADDR1); + // change default address of sensor 2 + WriteByte(0x212, addr2, ADDR1); + + SHDN_3 = 1; + VL6180_Init(ADDR1); + // change default address of sensor 3 + WriteByte(0x212, addr3, ADDR1); + + SHDN_4 = 1; + VL6180_Init(ADDR1); + // change default address of sensor 4 + WriteByte(0x212, addr4, ADDR1); + + SHDN_1 = 1; + VL6180_Init(ADDR1); + */ + + while (1) + { + range1 = sensor1.read(); + + /* + range2 = sensor2.read(); + range3 = sensor3.read(); + range4 = sensor4.read(); + */ + + pc.printf("Range one = %d | range two = %d | range three = %d | range four = %d\r\n",range1, range2, range3, range4); + wait_ms(100); + } +} +