Old working code

Dependencies:   mbed QEI ros_lib_melodic

main.cpp

Committer:
florine_van
Date:
2019-10-22
Revision:
2:c537f1ebad7b
Parent:
1:d5adc483bce0
Child:
3:a3144a45f44c

File content as of revision 2:c537f1ebad7b:

#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)

int main() {
    int range1; 
    int range2;
    int range3;
    int range4; 
    
    // Create sensors
    Sensor sensor1(I2C_SDA, I2C_SCL, PC_9);
    Sensor sensor2(I2C_SDA, I2C_SCL, PC_11);
    Sensor sensor3(I2C_SDA, I2C_SCL, PD_2);
    Sensor sensor4(I2C_SDA, I2C_SCL, PG_3);
 
    sensor1.turnOff();
    sensor2.turnOff();
    sensor3.turnOff();
    sensor4.turnOff();
    wait_ms(0.5);
 
    sensor1.turnOff();
    sensor2.turnOn();
    sensor3.turnOff();
    sensor4.turnOff();
    
    sensor2.init();
    sensor2.changeAddress(addr2);
    
    sensor3.turnOn();
    sensor3.init();
    sensor3.changeAddress(addr3);

    sensor4.turnOn();
    sensor4.init();
    sensor4.changeAddress(addr4);
    
    sensor1.turnOn();
    sensor1.init();
    /*
    // 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); 
    } 
}