Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Barnabybear
#39355 Hi, as 'jankop' says
Code: Select allanalogWrite(<GPIO_number>,<pwm_value>);

is the easyest way to get PWM on a GPIO. The ESP doesn't have a D to A converter so any analog output is a PWM output where the duty cycle is proportional to the required voltage.
User avatar
By vanderbreye
#39941 Now, i used the analogWrite(PIN,VAL) function, it works quite good. I'm using it with the TICKER Library ([url]https://github.com/sandeepmistry/esp8266-
Arduino/blob/master/esp8266com/esp8266/libraries/Ticker/Ticker.h[/url])

Code: Select all#include <Ticker.h>

/* LED-FADE */
void tick(int state) {
  if (fade == 1) val = val + state;
  if (fade == -1) val = val - state;
  if (fade == 1 && val >= 1023 - state) fade = -1;
  if (val > 1023) val = 1023;
  if (val < 1) val = 0;
  if (fade == -1 && val < 1 + state ) fade = 1;
  analogWrite(lightPin, val);
}


 Timer1.attach_ms(s, tick, 10); //2,1)


to speed up things, i use a custom delay function:


Code: Select allvoid delayMS(long howLong) {
  long end = micros() + howLong;
  while (micros() <= end)
  {
    yield();
  }
  return;
}


thanks, everyone!