Code du capteur du bateau à adapter au M5Stack

#include <Wire.h> #include <M5Stack.h> #include <VL53L1X.h>

VL53L1X sensor;

void setup() {

Serial.begin(115200);
Wire.begin();
Wire.setClock(400000); // use 400 kHz I2C
M5.begin();
sensor.setTimeout(500);
if (!sensor.init())
{
  Serial.println("Failed to detect and initialize sensor!");
  while (1);
}
sensor.setDistanceMode(VL53L1X::Long);
sensor.setMeasurementTimingBudget(15000);
sensor.startContinuous(15);
Serial.println("new program");

}

void loop() {

Serial.println(String(millis())+","+String(sensor.read()));
M5.Lcd.print(String(millis())+","+String(sensor.read()));

}

Code test du capteur ultrason pour M5Stack Bluetooth

#include <M5Stack.h>; #include “BluetoothSerial.h”; BluetoothSerial SerialBT; int trig = 2; int echo = 5; long lecture_echo; long cm; void setup(){

SerialBT.begin("M5Stack");
M5.begin();
M5.Power.begin();
pinMode(trig, OUTPUT);
digitalWrite(trig, LOW);
pinMode(echo, INPUT);

Serial.begin(9600); M5.Lcd.print(“Bienvenue sur les tutoriels d'IHM 3D”); M5.Lcd.print(cm); } void loop(){

digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
lecture_echo = pulseIn(echo,HIGH);
cm = lecture_echo /58;
M5.Lcd.print("Distance en cm :");
M5.Lcd.println(cm);
SerialBT.println(cm);
delay(1500);

}