This code also working but need to connect sensors to 1,2,3 ports of pahub, not to 0,1,2
#include <M5StickCPlus.h>
#include <Unit_Sonic.h>
#include "ClosedCube_TCA9548A.h"
#define PaHub_I2C_ADDRESS 0x70
ClosedCube::Wired::TCA9548A tca9548a;
SONIC_I2C sensor;
void setup() {
M5.begin();
tca9548a.address(PaHub_I2C_ADDRESS);
sensor.begin();
M5.Lcd.setTextFont(2);
}
void loop() {
static float newvalue = 0;
for (uint8_t channel = 0; channel < 3; channel++) {
tca9548a.selectChannel(channel);
M5.Lcd.printf("%i = ", channel);
newvalue = sensor.getDistance();
if ((newvalue < 4000) && (newvalue > 20)) {
M5.Lcd.printf("%.2fmm ", newvalue);
} else {
M5.Lcd.print("ERR ");
}
M5.Lcd.print("\n");
}
delay(20);
M5.Lcd.setCursor(0,0);
}