基础任务的成果发布在b站: https://www.bilibili.com/video/BV1kuD1YwERk/?vd_source=188a3fe7fed3cc24bda413a3b323c659
实现的基本功能:在ISO100感光值下,通过光传感器获得LUX值,然后工具公式算出曝光值,
在根据公式算出快门速度,光圈大小的关系。
然后展示在屏幕上。
完整代码:
#include <Adafruit_GFX.h> // Core graphics library #include <Adafruit_ST7789.h> // Hardware-specific library for ST7789 #include <SPI.h> #include <M5_DLight.h> // Use dedicated hardware SPI pins Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST); M5_DLight m5ligntSensor; uint8_t EV; float F = 1.0, T; uint8_t ISO = 100; void setup(void) { Serial.begin(115200); pinMode(5, INPUT_PULLUP); pinMode(6, INPUT_PULLUP); // turn on backlite pinMode(TFT_BACKLITE, OUTPUT); digitalWrite(TFT_BACKLITE, HIGH); // turn on the TFT / I2C power supply pinMode(TFT_I2C_POWER, OUTPUT); digitalWrite(TFT_I2C_POWER, HIGH); delay(10); // initialize TFT tft.init(135, 240); // Init ST7789 240x135 tft.setRotation(3); tft.fillScreen(ST77XX_BLACK); tft.setTextColor(ST77XX_WHITE); delay(1000); m5ligntSensor.begin(); m5ligntSensor.setMode(CONTINUOUSLY_H_RESOLUTION_MODE); } static uint8_t boolBtnPressed = false; static uint8_t prevLux = 0; void loop() { tft.setCursor(0, 0); tft.setTextSize(3); tft.println("HELLO EEPW"); boolBtnPressed = false; if (digitalRead(5) == LOW) { // tft.setCursor(0, 20); // tft.setTextSize(3); // tft.print("BTN 1 pressed"); F = 1.4; boolBtnPressed = true; } else if (digitalRead(6) == LOW) { // tft.setCursor(0, 20); // tft.setTextSize(3); // tft.print("BTN 2 pressed"); F = 2; boolBtnPressed = true; } delay(100); if (boolBtnPressed || (prevLux != m5ligntSensor.getLUX())) { prevLux = m5ligntSensor.getLUX(); tft.fillRect(0, 20, 240, 100, ST77XX_BLACK); tft.setCursor(0, 20); tft.print("LUX = "); tft.println(m5ligntSensor.getLUX()); tft.print("EV:"); EV = 2 + log2(m5ligntSensor.getLUX() / 10); tft.print(EV); tft.print(" ISO:"); tft.print(ISO); T = pow(2, log2(F * F) - EV); tft.println(); tft.setTextSize(2); tft.print("F:"); tft.print(F); tft.print(" T:"); tft.print(T, 3); } }