Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
33499beb32 | ||
|
|
38c81ae182 | ||
|
|
a8ceb258b8 | ||
|
|
7e5a6fac9f | ||
|
|
b7ba521c59 | ||
|
|
2b2a135bd5 | ||
|
|
a400b0464d |
@@ -54,6 +54,12 @@ else
|
|||||||
server.streamFile(f, mime::getContentType(SRH::_path), requestMethod);
|
server.streamFile(f, mime::getContentType(SRH::_path), requestMethod);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
LED_sequence_v1:
|
||||||
|
TODO:
|
||||||
|
- disable led stripes after defined time (webserver paramter?)
|
||||||
|
- define what to do if people enter stairs from different directions
|
||||||
|
- CAUTION: Sensor-Deadtime at LEAST 8 seconds
|
||||||
|
- --> switch off with person leaving stairs might not be possible
|
||||||
|
|
||||||
Webserver on v0.3.0 now working with LittleFS
|
Webserver on v0.3.0 now working with LittleFS
|
||||||
TODO:
|
TODO:
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
#ifndef __OTA_H
|
#ifndef __OTA_H
|
||||||
#define __OTA_H
|
#define __OTA_H
|
||||||
|
|
||||||
|
#include <ESP8266WiFi.h>
|
||||||
|
#include <WiFiUdp.h>
|
||||||
|
#include <ArduinoOTA.h>
|
||||||
|
|
||||||
void ota_setup() {
|
void ota_setup() {
|
||||||
ArduinoOTA.setPort(8266);
|
ArduinoOTA.setPort(8266);
|
||||||
ArduinoOTA.setHostname("ESP_Treppenlicht");
|
ArduinoOTA.setHostname("ESP_Treppenlicht");
|
||||||
|
|||||||
+9
-3
@@ -2,16 +2,22 @@
|
|||||||
|
|
||||||
#include "PCA9685.h"
|
#include "PCA9685.h"
|
||||||
|
|
||||||
|
#define SENSOR1 15
|
||||||
|
#define SENSOR2 12
|
||||||
|
|
||||||
|
#define INT_TIME 20 // interrupt intervall [ms]
|
||||||
class Treppe {
|
class Treppe {
|
||||||
private:
|
private:
|
||||||
uint8_t stairs;
|
uint8_t stairs;
|
||||||
uint16_t time_per_stair = 300; // dimmtime per stair [ms]
|
uint16_t time_per_stair = 200; // dimmtime per stair [ms]
|
||||||
uint16_t idle_brightness = 200;
|
uint16_t idle_brightness = 0;
|
||||||
uint16_t active_brightness = 2048;
|
uint16_t active_brightness = 1048;
|
||||||
|
|
||||||
uint8_t direction = 0;
|
uint8_t direction = 0;
|
||||||
|
uint8_t switch_direction = 0;
|
||||||
uint8_t state = 0;
|
uint8_t state = 0;
|
||||||
uint8_t switch_state = 0;
|
uint8_t switch_state = 0;
|
||||||
|
uint8_t finish = 1;
|
||||||
|
|
||||||
// initialize with i2c-Address 0, use Wire Library
|
// initialize with i2c-Address 0, use Wire Library
|
||||||
PCA9685 pwmController;
|
PCA9685 pwmController;
|
||||||
|
|||||||
@@ -9,11 +9,7 @@ extern "C" {
|
|||||||
#include "user_interface.h"
|
#include "user_interface.h"
|
||||||
}
|
}
|
||||||
// OTA & WEB
|
// OTA & WEB
|
||||||
#include <ESP8266WiFi.h>
|
|
||||||
#include <WiFiUdp.h>
|
|
||||||
#include <ArduinoOTA.h>
|
|
||||||
#include "ota.h"
|
#include "ota.h"
|
||||||
|
|
||||||
#include "wifi_credentials.h"
|
#include "wifi_credentials.h"
|
||||||
#include "httpserver.h"
|
#include "httpserver.h"
|
||||||
|
|
||||||
@@ -22,14 +18,11 @@ extern "C" {
|
|||||||
#define NODEMCU_LED 16
|
#define NODEMCU_LED 16
|
||||||
|
|
||||||
// PWM
|
// PWM
|
||||||
|
|
||||||
#include "pwm.h"
|
#include "pwm.h"
|
||||||
os_timer_t timer1;
|
os_timer_t timer1;
|
||||||
uint8_t timer_flag = 0;
|
uint8_t timer_flag = 0;
|
||||||
|
|
||||||
Treppe stairs(13);
|
Treppe stairs(13);
|
||||||
|
|
||||||
|
|
||||||
// WIFI
|
// WIFI
|
||||||
const char* ssid = STASSID;
|
const char* ssid = STASSID;
|
||||||
const char* password = STAPSK;
|
const char* password = STAPSK;
|
||||||
@@ -110,17 +103,9 @@ void setup() {
|
|||||||
|
|
||||||
os_timer_setfn(&timer1, timerCallback, &timer_flag);
|
os_timer_setfn(&timer1, timerCallback, &timer_flag);
|
||||||
os_timer_arm(&timer1, 20, true);
|
os_timer_arm(&timer1, 20, true);
|
||||||
|
|
||||||
stairs.setState(1);
|
|
||||||
stairs.setDirection(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if(millis() > 25000 && stairs.getState() == 1 && stairs.getDirection() == 1) stairs.setState(0);
|
|
||||||
if(millis() > 45000 && stairs.getDirection() == 1){
|
|
||||||
stairs.setState(1);
|
|
||||||
stairs.setDirection(0);
|
|
||||||
}
|
|
||||||
TIMEIF_US(ArduinoOTA.handle(), 1000, "OTA");
|
TIMEIF_US(ArduinoOTA.handle(), 1000, "OTA");
|
||||||
TIMEIF_US(httpServer.handleClient(), 1000, "HTTP");
|
TIMEIF_US(httpServer.handleClient(), 1000, "HTTP");
|
||||||
}
|
}
|
||||||
+53
-10
@@ -20,12 +20,10 @@ uint8_t Treppe::softstart_led(uint8_t led, uint16_t startval, uint16_t stopval){
|
|||||||
pwmController.setChannelPWM(led, (uint16_t)startval);
|
pwmController.setChannelPWM(led, (uint16_t)startval);
|
||||||
lastled = led;
|
lastled = led;
|
||||||
current_pwm = startval;
|
current_pwm = startval;
|
||||||
stepsize = 20*abs(stopval - startval)/(float)time_per_stair; // only valid at 1ms function call interval
|
stepsize = INT_TIME*abs(stopval - startval)/(float)time_per_stair; // only valid at 1ms function call interval
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(current_pwm > stopval - stepsize && current_pwm < stopval + stepsize) return 0;
|
|
||||||
// todo: duty cycle zero!
|
|
||||||
if(startval > stopval){
|
if(startval > stopval){
|
||||||
current_pwm -= stepsize;
|
current_pwm -= stepsize;
|
||||||
}
|
}
|
||||||
@@ -34,6 +32,10 @@ uint8_t Treppe::softstart_led(uint8_t led, uint16_t startval, uint16_t stopval){
|
|||||||
}
|
}
|
||||||
Serial.println((uint16_t)current_pwm);
|
Serial.println((uint16_t)current_pwm);
|
||||||
pwmController.setChannelPWM(led, (uint16_t)current_pwm);
|
pwmController.setChannelPWM(led, (uint16_t)current_pwm);
|
||||||
|
if(current_pwm > stopval - stepsize && current_pwm < stopval + stepsize){
|
||||||
|
if(stopval == 0) pwmController.setChannelPWM(led, 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +43,6 @@ void Treppe::ledsequence(){
|
|||||||
static int8_t led = 0;
|
static int8_t led = 0;
|
||||||
static uint16_t brightness = 0;
|
static uint16_t brightness = 0;
|
||||||
static uint16_t lastbrightness = 0;
|
static uint16_t lastbrightness = 0;
|
||||||
static uint8_t finish = 1;
|
|
||||||
static uint16_t status = 0;
|
static uint16_t status = 0;
|
||||||
uint16_t status_build = 0;
|
uint16_t status_build = 0;
|
||||||
status_build |= direction << 8;
|
status_build |= direction << 8;
|
||||||
@@ -94,17 +95,55 @@ void Treppe::ledsequence(){
|
|||||||
void Treppe::setup(){
|
void Treppe::setup(){
|
||||||
pwmController.resetDevices();
|
pwmController.resetDevices();
|
||||||
|
|
||||||
// Deactive PCA9685 due to LED Flickering
|
// Deactive PCA9685 Phase Balancer due to LED Flickering
|
||||||
// https://github.com/NachtRaveVL/PCA9685-Arduino/issues/15
|
// https://github.com/NachtRaveVL/PCA9685-Arduino/issues/15
|
||||||
// see also lib/PCA9685-Arduin/PCA9685.h:204
|
// see also lib/PCA9685-Arduin/PCA9685.h:204
|
||||||
pwmController.init(PCA9685_PhaseBalancer_None);
|
pwmController.init(PCA9685_PhaseBalancer_None);
|
||||||
pwmController.setPWMFrequency(200);
|
pwmController.setPWMFrequency(200);
|
||||||
|
pwmController.setAllChannelsPWM(idle_brightness);
|
||||||
|
|
||||||
|
pinMode(SENSOR1, INPUT);
|
||||||
|
pinMode(SENSOR2, INPUT);
|
||||||
Serial.println("Hello from Treppe");
|
Serial.println("Hello from Treppe");
|
||||||
Serial.print("Treppe: initial parameters: stairs=");
|
Serial.print("Treppe: initial parameters: stairs=");
|
||||||
Serial.println(stairs);
|
Serial.println(stairs);
|
||||||
}
|
}
|
||||||
void Treppe::task(){
|
void Treppe::task(){
|
||||||
ledsequence();
|
|
||||||
|
if(finish){
|
||||||
|
direction = switch_direction;
|
||||||
|
state = switch_state;
|
||||||
|
}
|
||||||
|
static uint8_t last_sensor_state[2] = {0,0};
|
||||||
|
uint8_t current_sensor_state[2] = {0,0};
|
||||||
|
current_sensor_state[0] = digitalRead(SENSOR1);
|
||||||
|
current_sensor_state[1] = digitalRead(SENSOR2);
|
||||||
|
|
||||||
|
if(current_sensor_state[0] && !last_sensor_state[0] && state == 0){
|
||||||
|
setDirection(1);
|
||||||
|
setState(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(current_sensor_state[1] && !last_sensor_state[1] && state == 0){
|
||||||
|
setDirection(0);
|
||||||
|
setState(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// first switch - off approach, use timer later
|
||||||
|
if(!current_sensor_state[0] && last_sensor_state[0] && state == 1){
|
||||||
|
setDirection(1);
|
||||||
|
setState(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!current_sensor_state[1] && last_sensor_state[1] && state == 1){
|
||||||
|
setDirection(0);
|
||||||
|
setState(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
last_sensor_state[0] = current_sensor_state[0];
|
||||||
|
last_sensor_state[1] = current_sensor_state[1];
|
||||||
|
ledsequence();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t Treppe::setIdle(uint16_t _idle_brightness){
|
uint16_t Treppe::setIdle(uint16_t _idle_brightness){
|
||||||
@@ -124,17 +163,21 @@ uint16_t Treppe::setTime(uint16_t _time_per_stair){
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t Treppe::setDirection(uint8_t _direction){
|
uint8_t Treppe::setDirection(uint8_t _direction){
|
||||||
direction = _direction;
|
switch_direction = _direction;
|
||||||
Serial.println("Treppe: Direction changed!");
|
Serial.println("Treppe: Direction changed!");
|
||||||
|
if(finish) Serial.println("apply direction request immediately");
|
||||||
|
else Serial.println("currently active, dir change afterwards");
|
||||||
// to do: implement state command variable to determine dimm-state
|
// to do: implement state command variable to determine dimm-state
|
||||||
return direction;
|
return switch_direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t Treppe::setState(uint8_t _state){
|
uint8_t Treppe::setState(uint8_t _state){
|
||||||
if(state == _state) return 1;
|
if(state == _state) return 1;
|
||||||
else{
|
else{
|
||||||
state = _state;
|
switch_state = _state;
|
||||||
Serial.println("Treppe: State changed!");
|
Serial.println("Treppe: State Request changed!");
|
||||||
|
if(finish) Serial.println("apply state request immediately");
|
||||||
|
else Serial.println("currently active, state changes after activity");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user