INT 21h

Hi, I am Vladimir Smagin, SysAdmin and Kaptain. Telegram Email / GIT / RSS / GPG

Smooth LED blink on Arduino, ESP8266, etc

№ 11244 В разделах: Electronics ESP8266 Programming от March 8th, 2021,
В подшивках: ,

Human eye can’t see led switching because its too fast, same effect used in old TV and displays with CRT, most of 7-segment indicators and other things. Change timings between on and off state to change brightness and effect duration.

int sv_max=20;
int sv_min=0;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  int pause_on=sv_min;
  int pause_off=sv_max;
  // Smooth turn on
  while(pause_on < sv_max) {
    pause_on++;
    pause_off--;
    digitalWrite(LED_BUILTIN, HIGH);
    delay(pause_on);
    digitalWrite(LED_BUILTIN, LOW);
    delay(pause_off);
  }
  pause_on=sv_max;
  pause_off=sv_min;
  // Smooth turn off
  while(pause_on > sv_min) {
    pause_on--;
    pause_off++;
    digitalWrite(LED_BUILTIN, HIGH);
    delay(pause_on);
    digitalWrite(LED_BUILTIN, LOW);
    delay(pause_off);
  }
}

Нет комментариев »

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Облачная платформа
Яндекс.Метрика

Fortune cookie: The whole religious complexion of the modern world is due to the absence from Jerusalem of a lunatic asylum. -- Havelock Ellis