Skip to content

Instantly share code, notes, and snippets.

@ksasao
Created February 1, 2022 16:35
Show Gist options
  • Save ksasao/4e813dc6fda880ed26be8a6a1f154d4e to your computer and use it in GitHub Desktop.
Save ksasao/4e813dc6fda880ed26be8a6a1f154d4e to your computer and use it in GitHub Desktop.
M5StickC 環境光センサ Hat。ロームのBH1750FVを利用 。 https://twitter.com/ksasao/status/1488550499549065218
#include <M5GFX.h>
#include <M5StickCPlus.h>
#include <M5_BH1750FVI.h>
M5GFX display;
M5_BH1750FVI sensor;
uint16_t lux;
void setup() {
M5.begin();
display.init();
display.setRotation(1);
sensor.begin();
//CONTINUOUSLY_H_RESOLUTION_MODE
//CONTINUOUSLY_H_RESOLUTION_MODE2
//CONTINUOUSLY_L_RESOLUTION_MODE
//ONE_TIME_H_RESOLUTION_MODE
//ONE_TIME_H_RESOLUTION_MODE2
//ONE_TIME_L_RESOLUTION_MODE
sensor.setMode(CONTINUOUSLY_H_RESOLUTION_MODE);
}
char txt[64];
void drawText(int lux){
sprintf(txt," %5d", lux);
display.setTextColor(TFT_WHITE, TFT_BLACK);
display.setTextWrap(false);
display.setTextDatum(textdatum_t::top_right);
display.setTextSize(0.75,1);
display.setFont(&fonts::Font8);
display.drawString(txt, 223,10);
display.setFont(&fonts::lgfxJapanGothic_40);
display.drawString("lux", 220,85);
}
void loop() {
lux = sensor.getLUX();
Serial.println(lux);
if (!display.displayBusy())
{
display.startWrite();
drawText(lux);
display.endWrite();
}
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment