Created
December 21, 2020 02:04
-
-
Save TakehikoShimojima/bc5008a6b1147a622dfdaa093134311a 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通信版) | |
*/ | |
#include <M5StickC.h> | |
#include <Wire.h> // Arduino standard I2C/Two-Wire Library | |
#include <TFMPI2C.h> // TFMini-Plus I2C Library v1.5.0 | |
TFMPI2C tfmP; // Create a TFMini-Plus I2C object | |
void setup() { | |
M5.begin(); | |
pinMode(0, INPUT_PULLUP); // SDAをプルアップする | |
pinMode(26, INPUT_PULLUP); // SCLをプルアップする | |
Wire.begin(0, 26); | |
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() { | |
tfmP.getData(tfDist, tfFlux, tfTemp); // Get a frame of data | |
if (tfmP.status == TFMP_READY) { // If no error... | |
M5.Lcd.fillScreen(BLACK); | |
M5.Lcd.setCursor(20, 20); | |
M5.Lcd.printf("%4dcm\r\n", tfDist); | |
M5.Lcd.printf("s: %d", tfFlux); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment