Created
December 24, 2020 08:23
-
-
Save TakehikoShimojima/cf9e9db7bd140e963fc4506719386ebc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* TFMini-SとM5StickCで距離を測る(I2C通信版) | |
* I2C Hubで複数のTFMiniーSを制御する | |
*/ | |
#include <M5StickC.h> | |
#include <Wire.h> // Arduino standard I2C/Two-Wire Library | |
#include "ClosedCube_TCA9548A.h" | |
#include <TFMPI2C.h> // TFMini-Plus I2C Library v1.5.0 | |
#define PaHub_I2C_ADDRESS 0x70 | |
ClosedCube::Wired::TCA9548A tca9548a; | |
#define NTFMini 5 // TFMini-Sの台数 | |
TFMPI2C tfmP; // Create a TFMini-Plus I2C object | |
void setup() { | |
M5.begin(); | |
Wire.begin(); | |
tca9548a.address(PaHub_I2C_ADDRESS); | |
M5.Lcd.setTextSize(2); | |
M5.Lcd.setRotation(3); | |
} | |
int16_t tfDist = 0; // Distance to object in centimeters | |
int16_t tfFlux = 0; // Signal strength or quality of return signal | |
int16_t tfTemp = 0; // Internal temperature of Lidar sensor chip | |
void loop() { | |
for (int ch = 0; ch < NTFMini; ch++) { | |
tca9548a.selectChannel(ch); | |
tfmP.getData(tfDist, tfFlux, tfTemp); // Get a frame of data | |
M5.Lcd.fillScreen(BLACK); | |
if (tfmP.status == TFMP_READY) { // If no error... | |
M5.Lcd.setCursor(0, 20); | |
M5.Lcd.printf("ch: %d\r\n", ch); | |
M5.Lcd.printf("%4dcm\r\n", tfDist); | |
M5.Lcd.printf("s: %d", tfFlux); | |
} | |
delay(500); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment