brightness measurement via LED
This commit is contained in:
parent
3cc9d2b6c1
commit
ab3c84e259
|
@ -55,12 +55,12 @@
|
|||
#endif
|
||||
|
||||
// Create Sensor Class
|
||||
#ifdef HAS_BME280
|
||||
#if defined HAS_BME280 || defined HAS_BME280_BRIGHTNESS
|
||||
#include <BME280.h>
|
||||
BME280 sensor;
|
||||
#endif
|
||||
|
||||
#ifdef HAS_SHT21
|
||||
#if defined HAS_SHT21 || defined HAS_SHT21_BRIGHTNESS
|
||||
#include <SHT21.h>
|
||||
SHT21 sensor;
|
||||
#endif
|
||||
|
@ -80,6 +80,33 @@ void blink(uint8_t num) {
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if defined HAS_SHT21_BRIGHTNESS || defined HAS_BME280_BRIGHTNESS
|
||||
|
||||
int16_t brightness()
|
||||
{
|
||||
unsigned int counter;
|
||||
// LED Anode auf OUTPUT/LOW
|
||||
pinMode(LED_A, OUTPUT);
|
||||
digitalWrite(LED_A, LOW);
|
||||
|
||||
// LED Kathode auf OUTPUT/HIGH
|
||||
pinMode(LED_K, OUTPUT);
|
||||
digitalWrite(LED_K, HIGH);
|
||||
delayMicroseconds(4);
|
||||
|
||||
// Kathode wieder auf INPUT
|
||||
pinMode(LED_K,INPUT);
|
||||
digitalWrite(LED_K, LOW);
|
||||
// In einer Schleife zählen, bis Kathode auf LOW geht
|
||||
for ( counter = 0; counter < 65000; counter++) {
|
||||
if (digitalRead(LED_K)==0) break;
|
||||
delayMicroseconds(5);
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Setup Wakeup Interrupt Timer
|
||||
void init_wdt()
|
||||
{
|
||||
|
@ -213,6 +240,13 @@ void loop()
|
|||
int32_t temperature;
|
||||
int32_t humidity;
|
||||
} __attribute__ ((packed)) data;
|
||||
#elif defined HAS_SHT21_BRIGHTNESS
|
||||
struct lora_data {
|
||||
uint8_t bat;
|
||||
int32_t temperature;
|
||||
int32_t humidity;
|
||||
int16_t brightness;
|
||||
} __attribute__ ((packed)) data;
|
||||
#elif defined HAS_BME280
|
||||
struct lora_data {
|
||||
uint8_t bat;
|
||||
|
@ -220,18 +254,30 @@ void loop()
|
|||
int32_t humidity;
|
||||
int32_t pressure;
|
||||
} __attribute__ ((packed)) data;
|
||||
#elif defined HAS_BME280_BRIGHTNESS
|
||||
struct lora_data {
|
||||
uint8_t bat;
|
||||
int32_t temperature;
|
||||
int32_t humidity;
|
||||
int32_t pressure;
|
||||
int16_t brightness;
|
||||
} __attribute__ ((packed)) data;
|
||||
#endif
|
||||
|
||||
// Get Sensor Data
|
||||
#ifdef HAS_BME280
|
||||
#if defined HAS_BME280 || defined HAS_BME280_BRIGHTNESS
|
||||
sensor.getData(&data.temperature, &data.pressure, &data.humidity);
|
||||
#endif
|
||||
|
||||
#ifdef HAS_SHT21
|
||||
#if defined HAS_SHT21 || defined HAS_SHT21_BRIGHTNESS
|
||||
data.temperature = (int32_t)(sensor.getTemperature()*100);
|
||||
data.humidity = (int32_t)(sensor.getHumidity()*100);
|
||||
#endif
|
||||
|
||||
#if defined HAS_SHT21_BRIGHTNESS || defined HAS_BME280_BRIGHTNESS
|
||||
data.brightness = (int16_t)(brightness());
|
||||
#endif
|
||||
|
||||
// Add Battery Voltage, 20mv steps, encoded into 1 Byte
|
||||
uint32_t batv = readVcc();
|
||||
data.bat = (uint8_t)(batv/20);
|
||||
|
|
|
@ -9,10 +9,17 @@
|
|||
#define HAS_NO_SENSOR - No Sensor, just send Battery Voltage (Beacon Mode)
|
||||
#define HAS_SHT21 - Sensirion SHT21 Temperature + Humidity Sensor
|
||||
#define HAS_BME280 - Bosch BME280 Temperature + Humidity + Pressure Sensor
|
||||
#define HAS_SHT21_BRIGHTNESS - SHT21 + Brightness via LED
|
||||
#define HAS_BME280_BRIGHTNESS - BME280 + Brightness via LED
|
||||
|
||||
* LED Support
|
||||
#define LED_PIN PIN_A7 - LED is connected to ATTiny84 Pin A7 on TinyTX SMD / TinyLora
|
||||
|
||||
* Brightness Measurement
|
||||
LED connected between 2 pins, switched in reverse direction for brightness measurement
|
||||
#define LED_K PIN_A7 - LED Cathode
|
||||
#define LED_A PIN_B2 - LED Anode
|
||||
|
||||
* Time between Measurements
|
||||
#define SLEEP_TIME 528 - Time in Seconds between Measurements. Try it out to get a good Approximation
|
||||
Examples from my Tests::
|
||||
|
@ -43,3 +50,12 @@
|
|||
#define RFM69_TXPOWER 31 // Transmitting Power 0-31, see datasheet for details
|
||||
#define RFM69_ENCKEY "0123456789ABCDEF" // AES encryption key, exactly 16 characters, if set messages will be encrypted using AES 128bit
|
||||
*/
|
||||
|
||||
/*
|
||||
// LoRa RFM95 + BME280 + Brightness Measurement
|
||||
#define RF_LORA
|
||||
#define HAS_BME280_BRIGHTNESS
|
||||
#define LED_K PIN_A7
|
||||
#define LED_A PIN_B2
|
||||
#define SLEEP_TIME 544 // ca
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue