Skip to content

Instantly share code, notes, and snippets.

@lazicdanilo
Created March 9, 2018 17:10
Show Gist options
  • Save lazicdanilo/7a6fe10570f7311fb6bef1ea3e30815f to your computer and use it in GitHub Desktop.
Save lazicdanilo/7a6fe10570f7311fb6bef1ea3e30815f to your computer and use it in GitHub Desktop.
#include <Wire.h>
#include <VL53L0X.h>
VL53L0X sensor;
VL53L0X sensor2;
VL53L0X sensor3;
VL53L0X sensor4;
VL53L0X sensor5;
void setup()
{
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(500);
Wire.begin();
Serial.begin (9600);
//SENSOR
pinMode(9, INPUT);
delay(150);
Serial.println("00");
sensor.init(true);
Serial.println("01");
delay(100);
sensor.setAddress((uint8_t)22);
Serial.println("02");
//SENSOR 2
pinMode(10, INPUT);
delay(150);
sensor2.init(true);
Serial.println("03");
delay(100);
sensor2.setAddress((uint8_t)25);
Serial.println("04");
//SENSOR 3
pinMode(11, INPUT);
delay(150);
sensor3.init(true);
Serial.println("05");
delay(100);
sensor3.setAddress((uint8_t)28);
Serial.println("06");
//SENSOR 4
pinMode(7, INPUT);
delay(150);
sensor4.init(true);
Serial.println("07");
delay(100);
sensor4.setAddress((uint8_t)31);
Serial.println("08");
//SENSOR 5
pinMode(8, INPUT);
delay(150);
sensor5.init(true);
Serial.println("09");
delay(100);
sensor5.setAddress((uint8_t)33);
Serial.println("10");
Serial.println("");
Serial.println("addresses set!!!!!");
Serial.println("");
Serial.println("");
sensor.setTimeout(500);
sensor2.setTimeout(500);
sensor3.setTimeout(500);
sensor4.setTimeout(500);
sensor5.setTimeout(500);
}
void loop()
{
Serial.println("__________________________________________________________________");
Serial.println("");
Serial.println("=================================");
Serial.println ("I2C scanner. Scanning ...");
byte count = 0;
//for (byte i = 1; i < 120; i++)
for (byte i = 1; i < 40; i++)
{
Wire.beginTransmission (i);
if (Wire.endTransmission () == 0)
{
Serial.print ("Found address: ");
Serial.print (i, DEC);
Serial.print (" (0x");
Serial.print (i, HEX);
Serial.println (")");
count++;
delay (1);
}
}
Serial.println ("Done.");
Serial.print ("Found ");
Serial.print (count, DEC);
Serial.println (" device(s).");
Serial.println("=================================");
long DISTANCE = (sensor.readRangeSingleMillimeters());
long DISTANCE_2 = (sensor2.readRangeSingleMillimeters());
long DISTANCE_3 = (sensor3.readRangeSingleMillimeters());
long DISTANCE_4 = (sensor4.readRangeSingleMillimeters());
long DISTANCE_5 = (sensor5.readRangeSingleMillimeters());
if (sensor.timeoutOccurred())
{
Serial.println("_________________________________");
Serial.print("Distance Sensor (READING): ");
Serial.println(" TIMEOUT");
Serial.println("_________________________________");
Serial.println("");
}
else
{
Serial.println("_________________________________");
Serial.print("Distance Sensor 1: ");
Serial.println(DISTANCE);
Serial.println("_________________________________");
Serial.println("");
}
if (sensor2.timeoutOccurred())
{
Serial.println("_________________________________");
Serial.print("Distance Sensor 2: ");
Serial.println(" TIMEOUT");
Serial.println("_________________________________");
Serial.println("");
}
else
{
Serial.println("_________________________________");
Serial.print("Distance Sensor 2: ");
Serial.println(DISTANCE_2);
Serial.println("_________________________________");
Serial.println("");
}
if (sensor3.timeoutOccurred())
{
Serial.println("_________________________________");
Serial.print("Distance Sensor 3: ");
Serial.println(" TIMEOUT");
Serial.println("_________________________________");
Serial.println("");
}
else
{
Serial.println("_________________________________");
Serial.print("Distance Sensor 3: ");
Serial.println(DISTANCE_3);
Serial.println("_________________________________");
Serial.println("");
}
if (sensor4.timeoutOccurred())
{
Serial.println("_________________________________");
Serial.print("Distance Sensor 4: ");
Serial.println(" TIMEOUT");
Serial.println("_________________________________");
Serial.println("");
}
else
{
Serial.println("_________________________________");
Serial.print("Distance Sensor 4: ");
Serial.println(DISTANCE_4);
Serial.println("_________________________________");
Serial.println("");
}
if (sensor5.timeoutOccurred())
{
Serial.println("_________________________________");
Serial.print("Distance Sensor 5: ");
Serial.println(" TIMEOUT");
Serial.println("_________________________________");
Serial.println("");
}
else
{
Serial.println("_________________________________");
Serial.print("Distance Sensor 5: ");
Serial.println(DISTANCE_5);
Serial.println("_________________________________");
Serial.println("");
}
Serial.println("__________________________________________________________________");
Serial.println();
Serial.println();
Serial.println();
Serial.println();
delay(1600);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment