Browse Source

copied project from sensoresp1

master
interfisch 1 year ago
commit
75f251b502
  1. 1
      .gitignore
  2. 67
      .travis.yml
  3. 142
      .vscode/c_cpp_properties.json
  4. 7
      .vscode/extensions.json
  5. 32
      .vscode/launch.json
  6. 39
      include/README
  7. 46
      lib/README
  8. 23
      platformio.ini
  9. 260
      src/main.cpp

1
.gitignore

@ -0,0 +1 @@
.pio

67
.travis.yml

@ -0,0 +1,67 @@
# Continuous Integration (CI) is the practice, in software
# engineering, of merging all developer working copies with a shared mainline
# several times a day < https://docs.platformio.org/page/ci/index.html >
#
# Documentation:
#
# * Travis CI Embedded Builds with PlatformIO
# < https://docs.travis-ci.com/user/integration/platformio/ >
#
# * PlatformIO integration with Travis CI
# < https://docs.platformio.org/page/ci/travis.html >
#
# * User Guide for `platformio ci` command
# < https://docs.platformio.org/page/userguide/cmd_ci.html >
#
#
# Please choose one of the following templates (proposed below) and uncomment
# it (remove "# " before each line) or use own configuration according to the
# Travis CI documentation (see above).
#
#
# Template #1: General project. Test it using existing `platformio.ini`.
#
# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# install:
# - pip install -U platformio
# - platformio update
#
# script:
# - platformio run
#
# Template #2: The project is intended to be used as a library with examples.
#
# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# env:
# - PLATFORMIO_CI_SRC=path/to/test/file.c
# - PLATFORMIO_CI_SRC=examples/file.ino
# - PLATFORMIO_CI_SRC=path/to/test/directory
#
# install:
# - pip install -U platformio
# - platformio update
#
# script:
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N

142
.vscode/c_cpp_properties.json

@ -0,0 +1,142 @@
{
"configurations": [
{
"name": "!!! WARNING !!! AUTO-GENERATED FILE, PLEASE DO NOT MODIFY IT AND USE https://docs.platformio.org/page/projectconf/section_env_build.html#build-flags"
},
{
"name": "Linux",
"includePath": [
"/media/fisch/HDD/Projects/iot_home/sensoresp3/include",
"/media/fisch/HDD/Projects/iot_home/sensoresp3/src",
"/media/fisch/HDD/Projects/iot_home/sensoresp3/.pio/libdeps/esp01_1m/Homie/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266mDNS/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266HTTPClient/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/DNSServer/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/Ticker/src",
"/media/fisch/HDD/Projects/iot_home/sensoresp3/.pio/libdeps/esp01_1m/ESP Async WebServer/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/Hash/src",
"/media/fisch/HDD/Projects/iot_home/sensoresp3/.pio/libdeps/esp01_1m/Bounce2/src",
"/media/fisch/HDD/Projects/iot_home/sensoresp3/.pio/libdeps/esp01_1m/AsyncMqttClient/src",
"/media/fisch/HDD/Projects/iot_home/sensoresp3/.pio/libdeps/esp01_1m/ESPAsyncTCP/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266WiFi/src",
"/media/fisch/HDD/Projects/iot_home/sensoresp3/.pio/libdeps/esp01_1m/ArduinoJson/src",
"/media/fisch/HDD/Projects/iot_home/sensoresp3/.pio/libdeps/esp01_1m/Adafruit BMP085 Library",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/Wire",
"/media/fisch/HDD/Projects/iot_home/sensoresp3/.pio/libdeps/esp01_1m/DHT sensor library",
"/media/fisch/HDD/Projects/iot_home/sensoresp3/.pio/libdeps/esp01_1m/Adafruit Unified Sensor",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/tools/sdk/include",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/tools/sdk/libc/xtensa-lx106-elf/include",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/cores/esp8266",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/tools/sdk/lwip2/include",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/variants/generic",
"/media/fisch/HDD/Projects/iot_home/sensoresp3/.pio/libdeps/esp01_1m/ESPAsyncTCP@1.2.0/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/ArduinoOTA",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/EEPROM",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266AVRISP/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266HTTPUpdateServer/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266LLMNR",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266NetBIOS",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266SSDP",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266SdFat/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266WebServer/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266WiFiMesh/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266httpUpdate/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/Ethernet/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/GDBStub/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/LittleFS/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/SD/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/SDFS/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/SPI",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/SPISlave/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/Servo/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/SoftwareSerial/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/TFT_Touch_Shield_V2",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/esp8266/src",
"/home/fisch/.platformio/packages/tool-unity",
""
],
"browse": {
"limitSymbolsToIncludedHeaders": true,
"path": [
"/media/fisch/HDD/Projects/iot_home/sensoresp3/include",
"/media/fisch/HDD/Projects/iot_home/sensoresp3/src",
"/media/fisch/HDD/Projects/iot_home/sensoresp3/.pio/libdeps/esp01_1m/Homie/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266mDNS/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266HTTPClient/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/DNSServer/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/Ticker/src",
"/media/fisch/HDD/Projects/iot_home/sensoresp3/.pio/libdeps/esp01_1m/ESP Async WebServer/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/Hash/src",
"/media/fisch/HDD/Projects/iot_home/sensoresp3/.pio/libdeps/esp01_1m/Bounce2/src",
"/media/fisch/HDD/Projects/iot_home/sensoresp3/.pio/libdeps/esp01_1m/AsyncMqttClient/src",
"/media/fisch/HDD/Projects/iot_home/sensoresp3/.pio/libdeps/esp01_1m/ESPAsyncTCP/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266WiFi/src",
"/media/fisch/HDD/Projects/iot_home/sensoresp3/.pio/libdeps/esp01_1m/ArduinoJson/src",
"/media/fisch/HDD/Projects/iot_home/sensoresp3/.pio/libdeps/esp01_1m/Adafruit BMP085 Library",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/Wire",
"/media/fisch/HDD/Projects/iot_home/sensoresp3/.pio/libdeps/esp01_1m/DHT sensor library",
"/media/fisch/HDD/Projects/iot_home/sensoresp3/.pio/libdeps/esp01_1m/Adafruit Unified Sensor",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/tools/sdk/include",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/tools/sdk/libc/xtensa-lx106-elf/include",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/cores/esp8266",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/tools/sdk/lwip2/include",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/variants/generic",
"/media/fisch/HDD/Projects/iot_home/sensoresp3/.pio/libdeps/esp01_1m/ESPAsyncTCP@1.2.0/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/ArduinoOTA",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/EEPROM",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266AVRISP/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266HTTPUpdateServer/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266LLMNR",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266NetBIOS",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266SSDP",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266SdFat/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266WebServer/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266WiFiMesh/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266httpUpdate/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/Ethernet/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/GDBStub/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/LittleFS/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/SD/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/SDFS/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/SPI",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/SPISlave/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/Servo/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/SoftwareSerial/src",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/TFT_Touch_Shield_V2",
"/home/fisch/.platformio/packages/framework-arduinoespressif8266/libraries/esp8266/src",
"/home/fisch/.platformio/packages/tool-unity",
""
]
},
"defines": [
"PLATFORMIO=40304",
"ESP8266",
"ARDUINO_ARCH_ESP8266",
"ARDUINO_ESP8266_ESP01",
"F_CPU=80000000L",
"__ets__",
"ICACHE_FLASH",
"ARDUINO=10805",
"ARDUINO_BOARD=\"PLATFORMIO_ESP01_1M\"",
"FLASHMODE_QIO",
"LWIP_OPEN_SRC",
"NONOSDK22x_190703=1",
"TCP_MSS=536",
"LWIP_FEATURES=1",
"LWIP_IPV6=0",
"VTABLES_IN_FLASH",
""
],
"intelliSenseMode": "clang-x64",
"cStandard": "c99",
"cppStandard": "c++11",
"compilerPath": "/home/fisch/.platformio/packages/toolchain-xtensa/bin/xtensa-lx106-elf-gcc",
"compilerArgs": [
"-mlongcalls",
"-mtext-section-literals",
""
]
}
],
"version": 4
}

7
.vscode/extensions.json

@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}

32
.vscode/launch.json

@ -0,0 +1,32 @@
// AUTOMATICALLY GENERATED FILE. PLEASE DO NOT MODIFY IT MANUALLY
// PIO Unified Debugger
//
// Documentation: https://docs.platformio.org/page/plus/debugging.html
// Configuration: https://docs.platformio.org/page/projectconf/section_env_debug.html
{
"version": "0.2.0",
"configurations": [
{
"type": "platformio-debug",
"request": "launch",
"name": "PIO Debug",
"executable": "/media/fisch/HDD/Projects/iot_home/sensoresp3/.pio/build/esp01_1m/firmware.elf",
"toolchainBinDir": "/home/fisch/.platformio/packages/toolchain-xtensa/bin",
"preLaunchTask": {
"type": "PlatformIO",
"task": "Pre-Debug"
},
"internalConsoleOptions": "openOnSessionStart"
},
{
"type": "platformio-debug",
"request": "launch",
"name": "PIO Debug (skip Pre-Debug)",
"executable": "/media/fisch/HDD/Projects/iot_home/sensoresp3/.pio/build/esp01_1m/firmware.elf",
"toolchainBinDir": "/home/fisch/.platformio/packages/toolchain-xtensa/bin",
"internalConsoleOptions": "openOnSessionStart"
}
]
}

39
include/README

@ -0,0 +1,39 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

46
lib/README

@ -0,0 +1,46 @@
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.
The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").
For example, see a structure of the following two libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html

23
platformio.ini

@ -0,0 +1,23 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:esp01_1m]
platform = espressif8266
board = esp01_1m
framework = arduino
monitor_port = /dev/ttyUSB0
monitor_speed = 115200
lib_deps =
DHT sensor library@1.3.10
Adafruit BMP085 Library@1.1.0
Homie@3.0.0

260
src/main.cpp

@ -0,0 +1,260 @@
//#define DEBUG
//ESP8266MOD als SMD Platine mit 1M Flash board=esp01_1m, statt wemos_d1
/*
* To Update configuration (wifi credentials) from data/homie/config.json:
* Connect to serial. On ESP-12E connect flash jumper
* Apply Power to ESP
* Optional: upload sketch pio run -t upload
* Flash SPIFFS data: pio run -t uploadfs
* Remove jumper, (reboot)
*/
#include "Arduino.h"
#include "DHT.h"
#include <Wire.h>
#include <Adafruit_BMP085.h>
/*
float humidityDHT; //[%RH]
float temperatureDHT; //[deg C]
float temperatureBMP; ///[deg C]
float pressure; // [hPa] BMP180
float light; //[Lux] LDR
bool movement //true bei pir output hight, false wenn low
*/
Adafruit_BMP085 bmp180;
//GPIO2 is blue led
DHT dht(13,DHT22,11); //default:11
#define PIRPIN 12
//timings
unsigned long lastsensorreadtime=0;
unsigned long sensorupdatedelay=60000; //delay for reading and transmitting
unsigned long lastPIRtime=0;
unsigned long PIRdelay=500;
bool motion=false;
unsigned long lastLDRtime=0;
unsigned long LDRdelay=5000;
int LDR_readcounter=0;
double LDRLightcommulative=0;
struct Values {
uint8_t id;
float humidityDHT; //[%RH]
float temperatureDHT; //[deg C]
float temperatureBMP; ///[deg C]
float pressureBMP; // [hPa]
float lightLDR; //[Lux]
int movementPIR; //[seconds with movement]
long rssi; //wifi rssi
};
Values values;
#include <Homie.h>
#define FW_NAME "sensoresp1"
#define FW_VERSION "1.0.0"
HomieNode sensorNode("sensors", "Sensors","sensors");
char tempstring[16]; //for dtostrf
// Light calibration data
// out[] holds the values wanted in lux/10
//measured 20160709
#define LDRARRAYSIZE 18
static const unsigned int out_ldr[] = {0, 30, 50, 60, 130, 170, 250, 420, 780, 1300,2600, 5000, 5350, 7700, 10900, 12000, 17000,20000}; // x10 (i.e. gets later divided by 10)
static const unsigned int in_ldr[] = {0, 12, 100, 150, 350, 400, 450, 650, 730, 780, 840, 930, 948 , 970, 993, 1005, 1019, 1023}; // 0 - 1023
void loopHandler();
double Light(int RawADC0);
double getAverageLight();
int get_lux(const unsigned int* _in, const unsigned int* _out, byte size);
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println("Welcome");
pinMode(PIRPIN, INPUT); //pir movement sensor
Serial.println("initializing ldr pinmode");
pinMode(A0, INPUT); //ldr
values.id=1;
Serial.println("initializing dht");
dht.begin(); // data pin 2
//Wire.begin(12,14); //i2c for bmp180
Serial.println("initializing bmp180");
//bmp180.init();
if (!bmp180.begin()){
Serial.println("#ERROR: BMP180 init fail\n\n");
}
Serial.println("connecting..");
Homie_setFirmware(FW_NAME, FW_VERSION);
Homie_setBrand(FW_NAME);
Homie.setLoopFunction(loopHandler);
sensorNode.advertise("temperatureDHT");
sensorNode.advertise("humidity");
sensorNode.advertise("temperatureBMP");
sensorNode.advertise("pressure");
sensorNode.advertise("light");
sensorNode.advertise("motion");
Homie.setup();
Serial.println("connected"); //wird nicht ausgegeben. keine ahnung warum.
}
void loop() {
Homie.loop();
}
void loopHandler() {
if (millis() >= (lastPIRtime+PIRdelay)){
if (digitalRead(PIRPIN)){
if (!motion) { //changed?
Homie.getLogger() << "motion " << ": " << "true" << endl;
sensorNode.setProperty("motion").send(String("true"));
}
motion=true;
}else{
if (motion) { //changed?
Homie.getLogger() << "motion " << ": " << "false" << endl;
sensorNode.setProperty("motion").send(String("false"));
}
motion=false;
}
lastPIRtime=millis();
}
if (millis() >= (lastLDRtime+LDRdelay)){
LDR_readcounter++;
//LDRLightcommulative+=Light(analogRead(A0)); //read light value from adc
float ldr_read = get_lux(in_ldr, out_ldr, LDRARRAYSIZE)/10.0;
LDRLightcommulative+=ldr_read;
lastLDRtime=millis();
}
if (millis() >= (lastsensorreadtime+sensorupdatedelay))
{
Serial.println("Sending");
if (WiFi.status() != WL_CONNECTED) //restart if wifi signal loss
{
ESP.reset();
}
float temperatureDHT = dht.readTemperature();
if (!(isnan(temperatureDHT) == 1)){ //success
Homie.getLogger() << "temperatureDHT " << ": " << temperatureDHT << endl;
sensorNode.setProperty("temperatureDHT").send(String(temperatureDHT));
}
float humidityDHT = dht.readHumidity();
if (!(isnan(humidityDHT) == 1)){ //success
Homie.getLogger() << "humidity " << ": " << humidityDHT << endl;
sensorNode.setProperty("humidity").send(String(humidityDHT));
}
//values.temperatureBMP=bmp180.bmp085GetTemperature(bmp180.bmp085ReadUT());
float temperatureBMP = bmp180.readTemperature();
Homie.getLogger() << "temperatureBMP " << ": " << temperatureBMP << endl;
sensorNode.setProperty("temperatureBMP").send(String(temperatureBMP));
//values.pressureBMP=bmp180.bmp085GetPressure(bmp180.bmp085ReadUP())/100.0; //Pa in hPa
//values.pressureBMP=bmp180.readPressure()/100.0;
float pressureBMP=bmp180.readPressure()/100.0;
Homie.getLogger() << "pressure " << ": " << pressureBMP << endl;
sensorNode.setProperty("pressure").send(String(pressureBMP));
float light=getAverageLight();
Homie.getLogger() << "light " << ": " << light << endl;
sensorNode.setProperty("light").send(String(light));
lastsensorreadtime=millis();
}
}
//////////////////////////////////////////////////////////////////////////////
// Calculate lux based on rawADC reading from LDR returns value in lux/10
//////////////////////////////////////////////////////////////////////////////
//quelle: https://groups.google.com/forum/#!topic/souliss/1kMAltPB2ME[1-25]
int get_lux(const unsigned int* _in, const unsigned int* _out, byte size)
{
// take care the value is within range
// val = constrain(val, _in[0], _in[size-1]);
unsigned int val = analogRead(A0);
#ifdef DEBUG //DEBUG++++++++++++++++
Serial.print("LDR RAW=: ");
Serial.println(val);
#endif
if (val <= _in[0]) return _out[0];
if (val >= _in[size-1]) return _out[size-1];
// search right interval
byte pos = 1; // _in[0] allready tested
while(val > _in[pos]) pos++;
// this will handle all exact "points" in the _in array
if (val == _in[pos]) return _out[pos];
// interpolate in the right segment for the rest
return map(val, _in[pos-1], _in[pos], _out[pos-1], _out[pos]);
}
double getAverageLight(){ //average all readings and reset
double ldravg=LDRLightcommulative/LDR_readcounter;
LDR_readcounter=0;
LDRLightcommulative=0;
return ldravg;
}
Loading…
Cancel
Save