Simon Schmidt 2 years ago
parent
commit
461c887ddf
1 changed files with 112 additions and 0 deletions
  1. 112
    0
      src/main.cpp

+ 112
- 0
src/main.cpp View File

@@ -180,8 +180,120 @@ uint32_t t;
#define SP_US(_str,_a) Serial.print(_str); Serial.print(" took: "); Serial.print(_a); Serial.println("µs")
#define TIMEIF_US(_str,_f, _l) t=micros(); _f; t=micros()-t; if(t > _l) { SP_US(_str, t); }

uint8_t softstart_led(uint8_t led, uint16_t startval, uint16_t stopval, uint8_t factor){
static uint8_t lastled = 255;
static uint8_t current_pwm = 0;
if(led != lastled){
pwmController.setChannelPWM(led, startval);
lastled = led;
current_pwm = startval;
return 1;
}
if(current_pwm == stopval){
return 0;
}

else if(startval > stopval){
current_pwm -= 1;
}
else {
current_pwm += 1;
}
pwmController.setChannelPWM(led, current_pwm*factor);
return 1;
}

#define LEDCOUNT 13

void ledsequence(uint8_t direction, uint8_t onoff, uint8_t factor){
static int8_t led = 0;
static uint8_t brightness = 0;
static uint8_t lastbrightness = 0;
static uint8_t finish = 1;
static uint32_t status = 0;
uint32_t status_build = 0;
status_build |= direction << 16;
status_build |= onoff << 8;
status_build |= factor;
if(status_build != status){ // check if any parameter changed
finish = 0; // set state unfinished -> start action
if(direction) led = 0; // reset led counter depending of direction
else led = LEDCOUNT-1;
if(onoff) brightness = 127; // set brightness value depending of on/off
else brightness = 0;
status = status_build; // set parameter memory
Serial.println("----Status Changed!");
}
if(!finish){ // finish == 0 -> action pending
if(!softstart_led(led,lastbrightness, brightness, factor)){
Serial.print("one LED finished, new set led: ");
Serial.print(led);
Serial.print(" last: ");
Serial.print(lastbrightness);
Serial.print(" curr: ");
Serial.println(brightness);
if(direction){
led++;
if(led >= LEDCOUNT) {
finish = 1;
lastbrightness = brightness;
}
}
else{
led--;
if(led < 0){
lastbrightness = brightness;
finish = 1;
}
}
}
}
}


void loop() {
<<<<<<< HEAD
static uint32_t dimmtimer = 0;
/* static uint8_t led = 0;
static uint16_t brightness = 127;
static uint16_t lastbrightness = 0;

if(millis() - dimmtimer > 2){
if(softstart_led(led, lastbrightness, brightness)){
// do nothing
}
else{
if(led < LEDCOUNT-1) led++;
else {
led = 0;
uint16_t mem = lastbrightness;
lastbrightness = brightness;
brightness = mem;
}
softstart_led((led), lastbrightness, brightness);
}
if(led >= LEDCOUNT){
//led = 0;
//uint16_t mem = lastbrightness;
//lastbrightness = brightness;
// brightness = mem;
}
dimmtimer = millis();
}*/

static uint8_t direction = 1;
static uint8_t onoff = 1;
if(millis() - dimmtimer > 2){
ledsequence(direction, onoff, 4);
}
if(millis() > 25000) onoff = 0;
TIMEIF_US("OTA", ArduinoOTA.handle(), 20000);
TIMEIF_US("HTTP", server.handleClient(), 20000);
=======
TIMEIF_US("OTA", ArduinoOTA.handle(), 1000);
TIMEIF_US("HTTP", server.handleClient(), 1000);
>>>>>>> d0b824963bd79fc436b4b312e49b48081860d8d4
}

Loading…
Cancel
Save