Dass Euch das so locker von der Hand geht.
Danke!
Werde mich heute noch dransetzen und ausprobieren.
Update 02:11 Uhr:
Leider bekomme ich nur den Helligkeitswert: 0
Tsl2561Dual.h
Code: Alles auswählen
// mit speziellen Dank an Jerome und papa!
// 20-07-2020
#ifndef __SENSORS_TSL2561_h__
#define __SENSORS_TSL2561_h__
#include <Sensors.h>
#include <Wire.h>
#include <TSL2561.h>
namespace as {
template <int ADDRESS_ONE=TSL2561_ADDR_LOW, int ADDRESS_TWO=TSL2561_ADDR_HIGH, uint8_t MODE=0>
class Tsl2561Dual : public Brightness {
public:
enum Mode { RETURN_TSL_MIN = 0, RETURN_TSL_MAX };
private:
::TSL2561 _tsl1;
::TSL2561 _tsl2;
bool _x16;
public:
Tsl2561Dual () : _tsl1(ADDRESS_ONE), _tsl2(ADDRESS_TWO), _x16(true) {}
void init () {
bool present1 = _tsl1.begin();
if (present1 == false) { DPRINT("TSL2561 not found at address ");DHEXLN((uint8_t)ADDRESS_ONE); }
bool present2 = _tsl2.begin();
if (present2 == false) { DPRINT("TSL2561 not found at address ");DHEXLN((uint8_t)ADDRESS_TWO); }
if( present1 == true && present2 == true) {
_tsl1.setGain(TSL2561_GAIN_16X);
_tsl2.setGain(TSL2561_GAIN_16X);
_tsl1.setTiming(TSL2561_INTEGRATIONTIME_101MS);
_tsl2.setTiming(TSL2561_INTEGRATIONTIME_101MS);
}
}
void measure (__attribute__((unused)) bool async=false) {
if( present() == true ) {
uint16_t b1 = _tsl1.getLuminosity(TSL2561_VISIBLE);
if( b1 > 63000 && _x16 == true ) {
_x16 = false;
_tsl1.setGain(TSL2561_GAIN_0X);
b1 = _tsl1.getLuminosity(TSL2561_VISIBLE);
}
else if ( b1 < 500 && _x16 == false ) {
_x16 = true;
_tsl1.setGain(TSL2561_GAIN_16X);
b1 = _tsl1.getLuminosity(TSL2561_VISIBLE);
}
uint16_t b2 = _tsl2.getLuminosity(TSL2561_VISIBLE);
if( b2 > 63000 && _x16 == true ) {
_x16 = false;
_tsl2.setGain(TSL2561_GAIN_0X);
b2 = _tsl2.getLuminosity(TSL2561_VISIBLE);
}
else if ( b2 < 500 && _x16 == false ) {
_x16 = true;
_tsl2.setGain(TSL2561_GAIN_16X);
b2= _tsl2.getLuminosity(TSL2561_VISIBLE);
}
DPRINT("Brightness 1: ");DDECLN(b1);
DPRINT("Brightness 2: ");DDECLN(b2);
switch (MODE) {
case RETURN_TSL_MIN:
_brightness = min(b1, b2);
break;
case RETURN_TSL_MAX:
_brightness = max(b1, b2);
break;
}
}
}
};
}
#endif
Code: Alles auswählen
//- -----------------------------------------------------------------------------------------------------------------------
// AskSin++
// 2016-10-31 papa Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
//- -----------------------------------------------------------------------------------------------------------------------
// define this to read the device id, serial and device type from bootloader section
// #define USE_OTA_BOOTLOADER
#define EI_NOTEXTERNAL
#include <EnableInterrupt.h>
#include <AskSinPP.h>
#include <LowPower.h>
// uncomment the following 2 lines if you have a TSL2561 connected at address 0x29
#include <Wire.h>
#include <sensors/Tsl2561Dual.h>
#include <MultiChannelDevice.h>
#include <Motion.h>
// we use a Pro Mini
// Arduino pin for the LED
// D4 == PIN 4 on Pro Mini
#define LED_PIN 4
// Arduino pin for the config button
// B0 == PIN 8 on Pro Mini
#define CONFIG_BUTTON_PIN 8
// Arduino pin for the PIR
// A0 == PIN 14 on Pro Mini
#define PIR_PIN1 14
#define PIR_PIN2 15
#define PIR_PIN3 16
#define PIR_PIN4 17
// number of available peers per channel
#define PEERS_PER_CHANNEL 6
// all library classes are placed in the namespace 'as'
using namespace as;
// define all device properties
const struct DeviceInfo PROGMEM devinfo = {
{0x56,0x78,0x90}, // Device ID
"EJ0000BM01", // Device Serial
{0x00,0x4a}, // Device Model
0x16, // Firmware Version
as::DeviceType::MotionDetector, // Device Type
{0x01,0x00} // Info Bytes
};
/**
* Configure the used hardware
*/
typedef AvrSPI<10,11,12,13> SPIType;
typedef Radio<SPIType,2> RadioType;
typedef StatusLed<LED_PIN> LedType;
typedef AskSin<LedType,NoBattery,RadioType> BaseHal;
class Hal : public BaseHal {
public:
void init (const HMID& id) {
BaseHal::init(id);
// set low voltage to 2.2V
// measure battery every 1h
//battery.init(seconds2ticks(60UL*60),sysclock);
//battery.low(22);
//battery.critical(19);
}
} hal;
#ifdef _TSL2561_H_
typedef MotionChannel<Hal,PEERS_PER_CHANNEL,List0,Tsl2561Dual<TSL2561_ADDR_LOW, TSL2561_ADDR_HIGH, Tsl2561Dual<>::RETURN_TSL_MAX> > MChannel;
#else
typedef MotionChannel<Hal,PEERS_PER_CHANNEL,List0> MChannel;
#endif
typedef MultiChannelDevice<Hal,MChannel,1> MotionType;
MotionType sdev(devinfo,0x20);
ConfigButton<MotionType> cfgBtn(sdev);
void setup () {
DINIT(57600,ASKSIN_PLUS_PLUS_IDENTIFIER);
sdev.init(hal);
buttonISR(cfgBtn,CONFIG_BUTTON_PIN);
motionISR(sdev,1,PIR_PIN1);
motionISR(sdev,2,PIR_PIN2);
motionISR(sdev,3,PIR_PIN3);
motionISR(sdev,4,PIR_PIN4);
sdev.initDone();
}
void loop() {
bool worked = hal.runready();
bool poll = sdev.pollRadio();
if( worked == false && poll == false ) {
// deep discharge protection
// if we drop below critical battery level - switch off all and sleep forever
//if( hal.battery.critical() ) {
// this call will never return
// hal.activity.sleepForever(hal);
// }
// if nothing to do - go sleep
hal.activity.savePower<Sleep<>>(hal);
}
}
Mit herzlichsten Grüßen
Er.win