OLED update interval

Hi!
I’m trying to ungerstand this code. It’s work fine:

esphome:
  name: test
  platform: ESP8266
  board: nodemcuv2

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password


  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Test Fallback Hotspot"
    password: !secret ap_password

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: !secret api_password

ota:
  password: !secret ota_password

  
# Time from Home Assistant
time:
  - platform: homeassistant
    id: homeassistant_time
    
display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    reset_pin: D0
    address: 0x3C
    lambda: |-
      // Displaying the clock with a blinking dot
      static int i = 0;
      i++;
      if ((i % 2) == 0)
        it.strftime(2, 0, id(sfdigital), "%H:%M", id(homeassistant_time).now());
      else
        it.strftime(2, 0, id(sfdigital), "%H %M", id(homeassistant_time).now());  
      // Displaying the day of the week
      it.strftime(15, 25, id(sfdigital1), "%A", id(homeassistant_time).now());
      // Date Display
      it.strftime(10, 37, id(sfdigital1), "%d-%m-%Y", id(homeassistant_time).now());

font:
  - file: "SFDigitalReadout.ttf"
    id: sfdigital
    size: 36
    
  - file: "SFDigitalReadout.ttf"
    id: sfdigital1
    size: 15

I can’t understand the code with a blinking dot: why does “i++” happen exactly once a second? The display refresh interval is not spelled out anywhere in the code …

1 Like

Probably because it is the default time interval for esphome ?
I can’t be sure of that but as looking the code you have a modulo operation that happens every refresh and if the modulo operation result is 0 the “:” are displayed. And then with a default refresh period of 1 sec this “:” will be the every 2 seconds for 1 second.

the logic of appear and desappear of “:” is clear for me. The question is only regarding refresh interval. In documentation on ESPHome (SSD1306 component):

  • update_interval (Optional, Time): The interval to re-draw the screen. Defaults to 5s.