This library allows you to read from multiple VL53L1X sensors.

Dependencies:   mbed

Fork of VL53L1X_Pololu by Jesus Fausto

Committer:
jvfausto
Date:
Wed Aug 08 21:44:33 2018 +0000
Revision:
1:e54ded4af43a
Child:
2:f570ff03fb81
Works with 4 sensors

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jvfausto 1:e54ded4af43a 1 #include "mbed.h"
jvfausto 1:e54ded4af43a 2 #include "VL53L1X.h"
jvfausto 1:e54ded4af43a 3 void resetPin(int pin);
jvfausto 1:e54ded4af43a 4
jvfausto 1:e54ded4af43a 5 Serial pc(USBTX,USBRX);
jvfausto 1:e54ded4af43a 6
jvfausto 1:e54ded4af43a 7 bool s1_init = false;
jvfausto 1:e54ded4af43a 8 bool s2_init = false;
jvfausto 1:e54ded4af43a 9 bool s3_init = false;
jvfausto 1:e54ded4af43a 10 bool s4_init = false;
jvfausto 1:e54ded4af43a 11
jvfausto 1:e54ded4af43a 12 VL53L1X sensor1(D14, D15, D0);
jvfausto 1:e54ded4af43a 13 VL53L1X sensor2(D14, D15, D1);
jvfausto 1:e54ded4af43a 14 VL53L1X sensor3(D14, D15, D2);
jvfausto 1:e54ded4af43a 15 VL53L1X sensor4(D14, D15, D3);
jvfausto 1:e54ded4af43a 16
jvfausto 1:e54ded4af43a 17 int count = 0;
jvfausto 1:e54ded4af43a 18 int main()
jvfausto 1:e54ded4af43a 19 {
jvfausto 1:e54ded4af43a 20 sensor1.turnOff();
jvfausto 1:e54ded4af43a 21 sensor2.turnOff();
jvfausto 1:e54ded4af43a 22 sensor3.turnOff();
jvfausto 1:e54ded4af43a 23 sensor4.turnOff();
jvfausto 1:e54ded4af43a 24 if (sensor2.initReading(0x25, 25000))
jvfausto 1:e54ded4af43a 25 {
jvfausto 1:e54ded4af43a 26 s2_init = true;
jvfausto 1:e54ded4af43a 27 }
jvfausto 1:e54ded4af43a 28 if (sensor1.initReading(0x27, 25000))
jvfausto 1:e54ded4af43a 29 {
jvfausto 1:e54ded4af43a 30 s1_init = true;
jvfausto 1:e54ded4af43a 31 }
jvfausto 1:e54ded4af43a 32 if (sensor3.initReading(0x35, 25000))
jvfausto 1:e54ded4af43a 33 {
jvfausto 1:e54ded4af43a 34 s3_init = true;
jvfausto 1:e54ded4af43a 35 }
jvfausto 1:e54ded4af43a 36 if (sensor4.initReading(0x37, 50000))
jvfausto 1:e54ded4af43a 37 {
jvfausto 1:e54ded4af43a 38 s4_init = true;
jvfausto 1:e54ded4af43a 39 }
jvfausto 1:e54ded4af43a 40 while(1)
jvfausto 1:e54ded4af43a 41 {
jvfausto 1:e54ded4af43a 42
jvfausto 1:e54ded4af43a 43 sensor1.startContinuous(50);
jvfausto 1:e54ded4af43a 44 sensor2.startContinuous(50);
jvfausto 1:e54ded4af43a 45 sensor3.startContinuous(50);
jvfausto 1:e54ded4af43a 46 sensor4.startContinuous(50);
jvfausto 1:e54ded4af43a 47
jvfausto 1:e54ded4af43a 48 if (s1_init)
jvfausto 1:e54ded4af43a 49 pc.printf("%d", sensor1.read());
jvfausto 1:e54ded4af43a 50 else
jvfausto 1:e54ded4af43a 51 pc.printf("-1");
jvfausto 1:e54ded4af43a 52
jvfausto 1:e54ded4af43a 53 pc.printf(",");
jvfausto 1:e54ded4af43a 54
jvfausto 1:e54ded4af43a 55 if (s2_init)
jvfausto 1:e54ded4af43a 56 pc.printf("%d", sensor2.read());
jvfausto 1:e54ded4af43a 57 else pc.printf("-1");
jvfausto 1:e54ded4af43a 58
jvfausto 1:e54ded4af43a 59 pc.printf(",");
jvfausto 1:e54ded4af43a 60
jvfausto 1:e54ded4af43a 61 if (s3_init)
jvfausto 1:e54ded4af43a 62 pc.printf("%d", sensor3.read());
jvfausto 1:e54ded4af43a 63 else pc.printf("-1");
jvfausto 1:e54ded4af43a 64
jvfausto 1:e54ded4af43a 65 pc.printf(",");
jvfausto 1:e54ded4af43a 66
jvfausto 1:e54ded4af43a 67 if (s4_init)
jvfausto 1:e54ded4af43a 68 pc.printf("%d", sensor4.read());
jvfausto 1:e54ded4af43a 69 else pc.printf("-1");
jvfausto 1:e54ded4af43a 70
jvfausto 1:e54ded4af43a 71 pc.printf("\r\n");
jvfausto 1:e54ded4af43a 72 sensor1.stopContinuous();
jvfausto 1:e54ded4af43a 73 sensor2.stopContinuous();
jvfausto 1:e54ded4af43a 74 sensor3.stopContinuous();
jvfausto 1:e54ded4af43a 75 sensor4.stopContinuous();
jvfausto 1:e54ded4af43a 76 wait(.02);
jvfausto 1:e54ded4af43a 77 }
jvfausto 1:e54ded4af43a 78 }