大家好
本次是测光笔的最后一个帖子
以下是摘抄的关于测光表的原理
测光表是一种用来测量光的强度之仪器。在摄影中,测光表用来确定适当的曝光时间。在胶片或感光元件之感光度和光缐强度已知的情况下, 测光表给出获得最佳曝光的光圈值和快门速度组合。测光表也用来控制照明的亮度,或者用作手持的仪器, 确保光强符合拍摄的要求。
关于相关计算公式见下图
基本原理在这里了
下面上系统框图
电路接线原理
实现步骤
首先根据公式由lux计算出光强
进而在光圈或快门确定的情况下求出另一个对象
舵机动作由板载按键D2控制
下面上代码
// SPDX-FileCopyrightText: 2022 Limor Fried for Adafruit Industries // // SPDX-License-Identifier: MIT #include <Arduino.h> #include <Adafruit_NeoPixel.h> #include <Adafruit_ST7789.h> #include <Fonts/FreeSans12pt7b.h> #include <BH1750.h> #include <Wire.h> BH1750 lightMeter; #include <ESP32Servo.h> Servo myservo; // create servo object to control a servo #if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3) int servoPin = 17; #elif defined(CONFIG_IDF_TARGET_ESP32C3) int servoPin = 7; #else int servoPin = 18; #endif Adafruit_ST7789 display = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST); GFXcanvas16 canvas(240, 135); float lux; void setup() { Serial.begin(115200); //while (! Serial) delay(10); delay(100); // Initialize the I2C bus (BH1750 library doesn't do this automatically) Wire.begin(); lightMeter.begin(BH1750::ONE_TIME_HIGH_RES_MODE); display.init(135, 240); // Init ST7789 240x135 display.setRotation(3); canvas.setFont(&FreeSans12pt7b); canvas.setTextColor(ST77XX_WHITE); pinMode(5, INPUT_PULLUP); pinMode(6, INPUT_PULLUP); pinMode(0, INPUT_PULLUP); pinMode(1, INPUT_PULLDOWN); pinMode(2, INPUT_PULLDOWN); // Allow allocation of all timers ESP32PWM::allocateTimer(0); ESP32PWM::allocateTimer(1); ESP32PWM::allocateTimer(2); ESP32PWM::allocateTimer(3); myservo.setPeriodHertz(50); // standard 50 hz servo myservo.attach(servoPin, 1000, 2000); // attaches the servo on pin 18 to the servo object } int j = 0; void loop() { // we use here the maxWait option due fail save if (lightMeter.measurementReady(true)) { lux = lightMeter.readLightLevel(); Serial.print(F("Light: ")); Serial.print(lux); Serial.println(F(" lx")); if (lux < 0) { Serial.println(F("Error condition detected")); } else { if (lux > 40000.0) { // reduce measurement time - needed in direct sun light if (lightMeter.setMTreg(32)) { Serial.println( F("Setting MTReg to low value for high light environment")); } else { Serial.println( F("Error setting MTReg to low value for high light environment")); } } else { if (lux > 10.0) { // typical light environment if (lightMeter.setMTreg(69)) { Serial.println(F( "Setting MTReg to default value for normal light environment")); } else { Serial.println(F("Error setting MTReg to default value for normal " "light environment")); } } else { if (lux <= 10.0) { // very low light environment if (lightMeter.setMTreg(138)) { Serial.println( F("Setting MTReg to high value for low light environment")); } else { Serial.println(F("Error setting MTReg to high value for low " "light environment")); } } } } } Serial.println(F("--------------------------------------")); } if (j % 2 == 0) { canvas.fillScreen(ST77XX_BLACK); canvas.setCursor(0, 17); canvas.setTextColor(ST77XX_YELLOW); canvas.println("Hello EEPW & DigiKey"); canvas.println("bigjiong"); canvas.setTextColor(ST77XX_WHITE); canvas.print("Lux:"); canvas.println(lux, 2); float ev_value = 2 + log(lux/10.0); canvas.setTextColor(ST77XX_RED); canvas.print("EV:"); canvas.println(ev_value, 2); display.drawRGBBitmap(0, 0, canvas.getBuffer(), 240, 135); pinMode(TFT_BACKLITE, OUTPUT); digitalWrite(TFT_BACKLITE, HIGH); } if (digitalRead(5)) { myservo.write(0); } else { myservo.write(90); } delay(10); return; }
此代码实现了lux以及EV数值的实时展示
并且可以通过按键控制舵机动作
下面来上效果图
舵机抬起
舵机按下
至此描述完毕
视频链接
https://www.bilibili.com/video/BV1Mw6KYME1A/