Compare commits
7
Commits
v0.4.0
...
b47f778fc1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b47f778fc1 | ||
|
|
c7eaffda00 | ||
|
|
69e1e869a5 | ||
|
|
1a284080e8 | ||
|
|
3490e7ba44 | ||
|
|
d059c3d72d | ||
|
|
55ebd21975 |
No files matched your search
@@ -72,3 +72,6 @@ LED Flickering issue
|
|||||||
https://github.com/NachtRaveVL/PCA9685-Arduino/issues/15
|
https://github.com/NachtRaveVL/PCA9685-Arduino/issues/15
|
||||||
|
|
||||||
PlatformIO Library veraltet
|
PlatformIO Library veraltet
|
||||||
|
|
||||||
|
|
||||||
|
###TIMER in OTA unterbrechen !!!!!
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "PCA9685.h"
|
|
||||||
|
|
||||||
#define SENSOR1 15
|
|
||||||
#define SENSOR2 12
|
|
||||||
|
|
||||||
#define INT_TIME 20 // interrupt intervall [ms]
|
|
||||||
class Treppe {
|
|
||||||
private:
|
|
||||||
uint8_t stairs;
|
|
||||||
uint16_t time_per_stair = 200; // dimmtime per stair [ms]
|
|
||||||
uint16_t idle_brightness = 0;
|
|
||||||
uint16_t active_brightness = 1048;
|
|
||||||
|
|
||||||
uint8_t direction = 0;
|
|
||||||
uint8_t switch_direction = 0;
|
|
||||||
uint8_t state = 0;
|
|
||||||
uint8_t switch_state = 0;
|
|
||||||
uint8_t finish = 1;
|
|
||||||
|
|
||||||
// initialize with i2c-Address 0, use Wire Library
|
|
||||||
PCA9685 pwmController;
|
|
||||||
uint8_t softstart_led(uint8_t led, uint16_t startval, uint16_t stopval);
|
|
||||||
void ledsequence();
|
|
||||||
|
|
||||||
public:
|
|
||||||
Treppe(uint8_t _stairs) : stairs(_stairs){}
|
|
||||||
void task(); // call periodically
|
|
||||||
|
|
||||||
void setup();
|
|
||||||
|
|
||||||
// Parameter section
|
|
||||||
uint16_t setIdle(uint16_t _idle_brightness);
|
|
||||||
uint16_t setActive(uint16_t _active_brightness);
|
|
||||||
uint16_t setTime(uint16_t _time_per_stair);
|
|
||||||
|
|
||||||
// Runtime Parameter section
|
|
||||||
uint8_t setDirection(uint8_t _direction);
|
|
||||||
uint8_t setState(uint8_t _state);
|
|
||||||
|
|
||||||
uint8_t getState() { return state;};
|
|
||||||
uint8_t getDirection() {return direction;};
|
|
||||||
};
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "pwm.h"
|
#include "treppe.h"
|
||||||
|
|
||||||
uint8_t Treppe::softstart_led(uint8_t led, uint16_t startval, uint16_t stopval){
|
uint8_t Treppe::softstart_led(uint8_t led, uint16_t startval, uint16_t stopval){
|
||||||
/*
|
/*
|
||||||
@@ -30,7 +30,7 @@ uint8_t Treppe::softstart_led(uint8_t led, uint16_t startval, uint16_t stopval){
|
|||||||
else {
|
else {
|
||||||
current_pwm += stepsize;
|
current_pwm += stepsize;
|
||||||
}
|
}
|
||||||
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(current_pwm > stopval - stepsize && current_pwm < stopval + stepsize){
|
||||||
if(stopval == 0) pwmController.setChannelPWM(led, 0);
|
if(stopval == 0) pwmController.setChannelPWM(led, 0);
|
||||||
@@ -60,39 +60,80 @@ void Treppe::ledsequence(){
|
|||||||
lastbrightness = active_brightness;
|
lastbrightness = active_brightness;
|
||||||
}
|
}
|
||||||
status = status_build; // set parameter memory
|
status = status_build; // set parameter memory
|
||||||
Serial.print("----Status Changed! onoff: ");
|
|
||||||
Serial.print(state);
|
|
||||||
Serial.print(" dir: ");
|
|
||||||
Serial.println(direction);
|
|
||||||
|
|
||||||
|
Serial.printf("----Status Changed! onoff: %d, dir: %d\n", state, direction);
|
||||||
}
|
}
|
||||||
if(!finish){ // finish == 0 -> action pending
|
if(!finish){ // finish == 0 -> action pending
|
||||||
if(!softstart_led(led,lastbrightness, brightness)){
|
if(!softstart_led(led,lastbrightness, brightness)){
|
||||||
Serial.print("one LED finished: ");
|
Serial.printf("one LED finished: led: %d, last: %d, curr %d\n",
|
||||||
Serial.print(led);
|
led, lastbrightness, brightness);
|
||||||
Serial.print(" last: ");
|
|
||||||
Serial.print(lastbrightness);
|
|
||||||
Serial.print(" curr: ");
|
|
||||||
Serial.println(brightness);
|
|
||||||
if(direction){
|
if(direction){
|
||||||
led++;
|
led++;
|
||||||
if(led >= stairs) {
|
if(led >= stairs)
|
||||||
finish = 1;
|
finish = 1;
|
||||||
//lastbrightness = brightness;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
led--;
|
led--;
|
||||||
if(led < 0){
|
if(led < 0)
|
||||||
//lastbrightness = brightness;
|
|
||||||
finish = 1;
|
finish = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Treppe::rampe()
|
||||||
|
{
|
||||||
|
if(state) {
|
||||||
|
finish = 0;
|
||||||
|
state = 0; // set parameter memory
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!finish) {
|
||||||
|
if(direction) { // aufwärts
|
||||||
|
if(tick >= ticks_treppe-1) { // ziel erreicht
|
||||||
|
Serial.println("[Treppe] oberster tick !");
|
||||||
|
finish = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
tick++; // eins hoch
|
||||||
|
}
|
||||||
|
else { // abwärts
|
||||||
|
if(tick <= 0) { // ziel erreicht
|
||||||
|
Serial.println("[Treppe] unterster tick !");
|
||||||
|
finish = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
tick--; // eins runter
|
||||||
|
}
|
||||||
|
|
||||||
|
stufe = tick / ticks_pro_stufe;
|
||||||
|
|
||||||
|
float new_pwm = 0.0;
|
||||||
|
if(an_aus) {
|
||||||
|
new_pwm = differenz_pwm_pro_tick * (tick - ticks_pro_stufe*stufe);
|
||||||
|
new_pwm += idle_brightness;
|
||||||
|
if(direction) new_pwm += differenz_pwm_pro_tick;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
new_pwm = active_brightness - differenz_pwm_pro_tick * (tick - ticks_pro_stufe*stufe);
|
||||||
|
new_pwm += idle_brightness;
|
||||||
|
if(direction) new_pwm -= differenz_pwm_pro_tick;
|
||||||
|
}
|
||||||
|
|
||||||
|
pwmController.setChannelPWM(stufe, (uint16_t) new_pwm);
|
||||||
|
Serial.printf("tick %04u, led %02d:%02u, pwm %4.1f\n",
|
||||||
|
tick,
|
||||||
|
stufe,
|
||||||
|
(tick - ticks_pro_stufe*stufe),
|
||||||
|
new_pwm
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Treppe::setup(){
|
void Treppe::setup(){
|
||||||
|
Serial.printf("differenz_pwm_pro_tick %f\n", differenz_pwm_pro_tick);
|
||||||
|
|
||||||
pwmController.resetDevices();
|
pwmController.resetDevices();
|
||||||
|
|
||||||
// Deactive PCA9685 Phase Balancer due to LED Flickering
|
// Deactive PCA9685 Phase Balancer due to LED Flickering
|
||||||
@@ -108,6 +149,7 @@ void Treppe::setup(){
|
|||||||
Serial.print("Treppe: initial parameters: stairs=");
|
Serial.print("Treppe: initial parameters: stairs=");
|
||||||
Serial.println(stairs);
|
Serial.println(stairs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Treppe::task(){
|
void Treppe::task(){
|
||||||
|
|
||||||
if(finish){
|
if(finish){
|
||||||
@@ -120,32 +162,41 @@ void Treppe::task(){
|
|||||||
current_sensor_state[1] = digitalRead(SENSOR2);
|
current_sensor_state[1] = digitalRead(SENSOR2);
|
||||||
|
|
||||||
if(current_sensor_state[0] && !last_sensor_state[0] && state == 0){
|
if(current_sensor_state[0] && !last_sensor_state[0] && state == 0){
|
||||||
|
setTick(0);
|
||||||
|
setAnAus(1);
|
||||||
setDirection(1);
|
setDirection(1);
|
||||||
setState(1);
|
setState(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(current_sensor_state[1] && !last_sensor_state[1] && state == 0){
|
if(current_sensor_state[1] && !last_sensor_state[1] && state == 0){
|
||||||
|
setTick(0);
|
||||||
|
setAnAus(0);
|
||||||
setDirection(0);
|
setDirection(0);
|
||||||
setState(1);
|
setState(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// first switch - off approach, use timer later
|
// first switch - off approach, use timer later
|
||||||
if(!current_sensor_state[0] && last_sensor_state[0] && state == 1){
|
if(!current_sensor_state[0] && last_sensor_state[0] && state == 1){
|
||||||
|
setTick(ticks_treppe);
|
||||||
|
setAnAus(1);
|
||||||
setDirection(1);
|
setDirection(1);
|
||||||
setState(0);
|
setState(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!current_sensor_state[1] && last_sensor_state[1] && state == 1){
|
if(!current_sensor_state[1] && last_sensor_state[1] && state == 1){
|
||||||
|
setTick(ticks_treppe);
|
||||||
|
setAnAus(1);
|
||||||
setDirection(0);
|
setDirection(0);
|
||||||
setState(0);
|
setState(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
last_sensor_state[0] = current_sensor_state[0];
|
last_sensor_state[0] = current_sensor_state[0];
|
||||||
last_sensor_state[1] = current_sensor_state[1];
|
last_sensor_state[1] = current_sensor_state[1];
|
||||||
ledsequence();
|
|
||||||
|
|
||||||
|
ledsequence();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint16_t Treppe::setIdle(uint16_t _idle_brightness){
|
uint16_t Treppe::setIdle(uint16_t _idle_brightness){
|
||||||
idle_brightness = _idle_brightness;
|
idle_brightness = _idle_brightness;
|
||||||
Serial.println("Treppe: idle brightness changed!");
|
Serial.println("Treppe: idle brightness changed!");
|
||||||
@@ -162,22 +213,20 @@ uint16_t Treppe::setTime(uint16_t _time_per_stair){
|
|||||||
return time_per_stair;
|
return time_per_stair;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t Treppe::setDirection(uint8_t _direction){
|
void Treppe::setDirection(uint8_t _direction){
|
||||||
switch_direction = _direction;
|
switch_direction = _direction;
|
||||||
Serial.println("Treppe: Direction changed!");
|
Serial.printf("Treppe: switch_direction=%d!\n", switch_direction);
|
||||||
if(finish) Serial.println("apply direction request immediately");
|
if(finish) Serial.println("apply direction request immediately");
|
||||||
else Serial.println("currently active, dir change afterwards");
|
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 switch_direction;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t Treppe::setState(uint8_t _state){
|
void Treppe::setState(uint8_t _state){
|
||||||
if(state == _state) return 1;
|
if(state == _state) return;
|
||||||
else{
|
else {
|
||||||
switch_state = _state;
|
switch_state = _state;
|
||||||
Serial.println("Treppe: State Request changed!");
|
Serial.printf("Treppe: switch_state=%d!\n", switch_state);
|
||||||
if(finish) Serial.println("apply state request immediately");
|
if(finish) Serial.println("apply state request immediately");
|
||||||
else Serial.println("currently active, state changes after activity");
|
else Serial.println("currently active, state changes after activity");
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "PCA9685.h"
|
||||||
|
|
||||||
|
#define SENSOR1 15
|
||||||
|
#define SENSOR2 12
|
||||||
|
|
||||||
|
#define INT_TIME 20 // interrupt intervall [ms]
|
||||||
|
|
||||||
|
class Treppe {
|
||||||
|
private:
|
||||||
|
uint8_t stairs;
|
||||||
|
uint16_t time_per_stair = 300; // dimmtime per stair [ms]
|
||||||
|
uint16_t idle_brightness = 0;
|
||||||
|
uint16_t active_brightness = 500;
|
||||||
|
|
||||||
|
uint8_t direction = 0;
|
||||||
|
uint8_t switch_direction = 0;
|
||||||
|
uint8_t state = 0;
|
||||||
|
uint8_t switch_state = 0;
|
||||||
|
uint8_t finish = 1;
|
||||||
|
|
||||||
|
// alternative
|
||||||
|
uint32_t tick = 0;
|
||||||
|
uint32_t stufe = 0;
|
||||||
|
uint8_t an_aus = 0;
|
||||||
|
|
||||||
|
uint32_t ticks_treppe = 0;
|
||||||
|
uint32_t ticks_pro_stufe = 0;
|
||||||
|
float differenz_pwm_pro_tick = 0.0;
|
||||||
|
// alternative
|
||||||
|
|
||||||
|
|
||||||
|
// initialize with i2c-Address 0, use Wire Library
|
||||||
|
PCA9685 pwmController;
|
||||||
|
uint8_t softstart_led(uint8_t led, uint16_t startval, uint16_t stopval);
|
||||||
|
void ledsequence();
|
||||||
|
void rampe();
|
||||||
|
|
||||||
|
public:
|
||||||
|
Treppe(uint8_t _stairs) : stairs(_stairs){
|
||||||
|
ticks_pro_stufe = time_per_stair / 20; // [ms]
|
||||||
|
ticks_treppe = ticks_pro_stufe * stairs;
|
||||||
|
|
||||||
|
differenz_pwm_pro_tick = (float) (active_brightness - idle_brightness)
|
||||||
|
/ (float) ticks_pro_stufe;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup();
|
||||||
|
void task(); // call periodically
|
||||||
|
|
||||||
|
// Parameter section
|
||||||
|
uint16_t setIdle(uint16_t _idle_brightness);
|
||||||
|
uint16_t setActive(uint16_t _active_brightness);
|
||||||
|
uint16_t setTime(uint16_t _time_per_stair);
|
||||||
|
|
||||||
|
void setTick(uint32_t _tick) {
|
||||||
|
tick = _tick;
|
||||||
|
Serial.printf("Treppe: Tick: %u!\n", tick);
|
||||||
|
}
|
||||||
|
uint32_t getTicks() {
|
||||||
|
return ticks_treppe;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Runtime Parameter section
|
||||||
|
void setDirection(uint8_t _direction);
|
||||||
|
void setState(uint8_t _state);
|
||||||
|
void setAnAus(uint8_t _an_aus) {
|
||||||
|
an_aus = _an_aus;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t getState() { return state;};
|
||||||
|
uint8_t getFinished() { return finish;};
|
||||||
|
uint8_t getDirection() {return direction;};
|
||||||
|
};
|
||||||
+19
-4
@@ -18,10 +18,10 @@ extern "C" {
|
|||||||
#define NODEMCU_LED 16
|
#define NODEMCU_LED 16
|
||||||
|
|
||||||
// PWM
|
// PWM
|
||||||
#include "pwm.h"
|
#include "treppe.h"
|
||||||
os_timer_t timer1;
|
os_timer_t timer1;
|
||||||
uint8_t timer_flag = 0;
|
uint8_t timer_flag = 0;
|
||||||
Treppe stairs(13);
|
Treppe stairs(16);
|
||||||
|
|
||||||
// WIFI
|
// WIFI
|
||||||
const char* ssid = STASSID;
|
const char* ssid = STASSID;
|
||||||
@@ -105,7 +105,22 @@ void setup() {
|
|||||||
os_timer_arm(&timer1, 20, true);
|
os_timer_arm(&timer1, 20, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <random>
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
TIMEIF_US(ArduinoOTA.handle(), 1000, "OTA");
|
// if(stairs.getState() == 0) {
|
||||||
TIMEIF_US(httpServer.handleClient(), 1000, "HTTP");
|
// delay(1000);
|
||||||
|
|
||||||
|
// // uint32_t t = rand() % stairs.getTicks();
|
||||||
|
// // uint32_t d = rand() % 2;
|
||||||
|
|
||||||
|
// // stairs.setTick(t);
|
||||||
|
// // stairs.setDirection(d);
|
||||||
|
|
||||||
|
// stairs.setDirection(!stairs.getDirection());
|
||||||
|
// stairs.setState(1);
|
||||||
|
// }
|
||||||
|
|
||||||
|
TIMEIF_US(ArduinoOTA.handle(), 10000, "OTA");
|
||||||
|
TIMEIF_US(httpServer.handleClient(), 10000, "HTTP");
|
||||||
}
|
}
|
||||||
+30
-30
@@ -1,40 +1,40 @@
|
|||||||
#include <Arduino.h>
|
// #include <Arduino.h>
|
||||||
#include <unity.h>
|
// #include <unity.h>
|
||||||
|
|
||||||
String STR_TO_TEST;
|
// String STR_TO_TEST;
|
||||||
|
|
||||||
void setUp(void) {
|
// // void setUp(void) {
|
||||||
// set stuff up here
|
// // // set stuff up here
|
||||||
STR_TO_TEST = "Hello, world!";
|
// // STR_TO_TEST = "Hello, world!";
|
||||||
}
|
// // }
|
||||||
|
|
||||||
void tearDown(void) {
|
// // void tearDown(void) {
|
||||||
// clean stuff up here
|
// // // clean stuff up here
|
||||||
STR_TO_TEST = "";
|
// // STR_TO_TEST = "";
|
||||||
}
|
// // }
|
||||||
|
|
||||||
void test_led_builtin_pin_number(void) {
|
// void test_led_builtin_pin_number(void) {
|
||||||
TEST_ASSERT_EQUAL(2, LED_BUILTIN);
|
// TEST_ASSERT_EQUAL(2, LED_BUILTIN);
|
||||||
}
|
// }
|
||||||
|
|
||||||
void test_string_concat(void) {
|
// void test_string_concat(void) {
|
||||||
String hello = "Hello, ";
|
// String hello = "Hello, ";
|
||||||
String world = "world!";
|
// String world = "world!";
|
||||||
TEST_ASSERT_EQUAL_STRING(STR_TO_TEST.c_str(), (hello + world).c_str());
|
// TEST_ASSERT_EQUAL_STRING(STR_TO_TEST.c_str(), (hello + world).c_str());
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
void setup()
|
// void setup()
|
||||||
{
|
// {
|
||||||
delay(2000); // service delay
|
// delay(2000); // service delay
|
||||||
UNITY_BEGIN();
|
// UNITY_BEGIN();
|
||||||
|
|
||||||
RUN_TEST(test_led_builtin_pin_number);
|
// RUN_TEST(test_led_builtin_pin_number);
|
||||||
RUN_TEST(test_string_concat);
|
// RUN_TEST(test_string_concat);
|
||||||
|
|
||||||
UNITY_END(); // stop unit testing
|
// UNITY_END(); // stop unit testing
|
||||||
}
|
// }
|
||||||
|
|
||||||
void loop()
|
// void loop()
|
||||||
{
|
// {
|
||||||
}
|
// }
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#include "treppe.h"
|
||||||
|
|
||||||
|
#include <unity.h>
|
||||||
|
|
||||||
|
Treppe stairs(10);
|
||||||
|
|
||||||
|
void setUp(void) {
|
||||||
|
// run before each test
|
||||||
|
// set stuff up here
|
||||||
|
stairs.setup();
|
||||||
|
Serial.println("Treppe initialized !");
|
||||||
|
Serial.println("PCA9685 connected !");
|
||||||
|
}
|
||||||
|
|
||||||
|
void tearDown(void) {
|
||||||
|
// clean stuff up here
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_set_state(void) {
|
||||||
|
stairs.setState(1);
|
||||||
|
TEST_ASSERT_EQUAL(1, stairs.getState());
|
||||||
|
stairs.setState(0);
|
||||||
|
TEST_ASSERT_EQUAL(0, stairs.getState());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void test_set_direction(void) {
|
||||||
|
stairs.setDirection(1);
|
||||||
|
TEST_ASSERT_EQUAL(1, stairs.getDirection());
|
||||||
|
stairs.setDirection(0);
|
||||||
|
TEST_ASSERT_EQUAL(0, stairs.getDirection());
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
delay(2000); // service delay
|
||||||
|
UNITY_BEGIN();
|
||||||
|
|
||||||
|
RUN_TEST(test_set_state);
|
||||||
|
RUN_TEST(test_set_direction);
|
||||||
|
|
||||||
|
UNITY_END(); // stop unit testing
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
}
|
||||||
Reference in new issue
Block a user