nene1234

lilka + display + battery + button + server

Nov 9th, 2025 (edited)
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 5.14 KB | Source Code | 0 0
  1. esphome:
  2.   name: lilka
  3.   friendly_name: lilka
  4.   on_boot:
  5.     priority: 600
  6.     then:
  7.       - output.turn_on: display_power
  8.       - delay: 100ms
  9.  
  10. esp32:
  11.   board: esp32-s3-devkitc-1
  12.   framework:
  13.     type: esp-idf
  14.  
  15. logger:
  16. api:
  17.   encryption:
  18.     key: "Yw3yq8lxsaze+jdggjAwxKpV4GD6gNZptvw4d6OPfOc="
  19.  
  20. ota:
  21.   - platform: esphome
  22.     password: "bb198feb99159fdaefc8092f10039acd"
  23.  
  24. wifi:
  25.   ssid: !secret wifi_ssid
  26.   password: !secret wifi_password
  27.   ap:
  28.     ssid: "Lilka Fallback Hotspot"
  29.     password: "hnYImYM4O6I0"
  30.  
  31. captive_portal:
  32. web_server:
  33.   port: 80
  34.  
  35. # Живлення дисплея
  36. output:
  37.   - platform: gpio
  38.     pin: 46
  39.     id: display_power
  40.     inverted: false
  41.  
  42. # Глобальні змінні для підрахунку натискань
  43. globals:
  44.   - id: up_count
  45.     type: int
  46.     restore_value: no
  47.     initial_value: '0'
  48.   - id: down_count
  49.     type: int
  50.     restore_value: no
  51.     initial_value: '0'
  52.   - id: left_count
  53.     type: int
  54.     restore_value: no
  55.     initial_value: '0'
  56.   - id: right_count
  57.     type: int
  58.     restore_value: no
  59.     initial_value: '0'
  60.  
  61. # Кнопки
  62. binary_sensor:
  63.   - platform: gpio
  64.     pin:
  65.       number: 38
  66.       mode: INPUT_PULLUP
  67.       inverted: true
  68.     name: "Button Up"
  69.     id: button_up
  70.     filters:
  71.       - delayed_on: 10ms
  72.     on_press:
  73.       then:
  74.         - logger.log: "UP pressed"
  75.         - globals.set:
  76.             id: up_count
  77.             value: !lambda 'return id(up_count) + 1;'
  78.    
  79.   - platform: gpio
  80.     pin:
  81.       number: 41
  82.       mode: INPUT_PULLUP
  83.       inverted: true
  84.     name: "Button Down"
  85.     id: button_down
  86.     filters:
  87.       - delayed_on: 10ms
  88.     on_press:
  89.       then:
  90.         - logger.log: "DOWN pressed"
  91.         - globals.set:
  92.             id: down_count
  93.             value: !lambda 'return id(down_count) + 1;'
  94.    
  95.   - platform: gpio
  96.     pin:
  97.       number: 39
  98.       mode: INPUT_PULLUP
  99.       inverted: true
  100.     name: "Button Left"
  101.     id: button_left
  102.     filters:
  103.       - delayed_on: 10ms
  104.     on_press:
  105.       then:
  106.         - logger.log: "LEFT pressed"
  107.         - globals.set:
  108.             id: left_count
  109.             value: !lambda 'return id(left_count) + 1;'
  110.    
  111.   - platform: gpio
  112.     pin:
  113.       number: 40
  114.       mode: INPUT_PULLUP
  115.       inverted: true
  116.     name: "Button Right"
  117.     id: button_right
  118.     filters:
  119.       - delayed_on: 10ms
  120.     on_press:
  121.       then:
  122.         - logger.log: "RIGHT pressed"
  123.         - globals.set:
  124.             id: right_count
  125.             value: !lambda 'return id(right_count) + 1;'
  126.  
  127. # Батарея
  128. sensor:
  129.   - platform: adc
  130.     pin: GPIO3
  131.     name: "Battery Voltage"
  132.     id: battery_voltage
  133.     update_interval: 10s
  134.     attenuation: 11db
  135.     filters:
  136.       - multiply: 1.33
  137.      
  138.   - platform: template
  139.     name: "Battery Level"
  140.     id: battery_level
  141.     unit_of_measurement: "%"
  142.     accuracy_decimals: 0
  143.     update_interval: 10s
  144.     lambda: |-
  145.       float voltage = id(battery_voltage).state;
  146.       float percent = (voltage - 3.0) / (4.2 - 3.0) * 100.0;
  147.       if (percent > 100) percent = 100;
  148.       if (percent < 0) percent = 0;
  149.       return percent;
  150.  
  151. # SPI
  152. spi:
  153.   clk_pin: 18
  154.   mosi_pin: 17
  155.  
  156. # Шрифти
  157. font:
  158.   - file: "gfonts://Roboto"
  159.     id: font_small
  160.     size: 16
  161.   - file: "gfonts://Roboto"
  162.     id: font_large
  163.     size: 24
  164.  
  165. # Дисплей (поки БЕЗ LVGL)
  166. display:
  167.   - platform: mipi_spi
  168.     model: ST7789V
  169.     dc_pin: 15
  170.     cs_pin: 7
  171.     update_interval: 100ms
  172.     rotation: 270
  173.     invert_colors: false
  174.     color_order: RGB
  175.     pixel_mode: 16bit
  176.     dimensions:
  177.       width: 240
  178.       height: 280
  179.       offset_width: 0
  180.       offset_height: 0
  181.     lambda: |-
  182.       // Фон
  183.       it.fill(Color::BLACK);
  184.      
  185.       // Заголовок
  186.       it.print(120, 20, id(font_large), Color::WHITE, TextAlign::CENTER, "Button Test");
  187.      
  188.       // Лінія
  189.       it.line(20, 50, 220, 50, Color(50, 50, 50));
  190.      
  191.       // Батарея
  192.       if (id(battery_level).has_state()) {
  193.         it.printf(120, 60, id(font_small), Color(0, 255, 0), TextAlign::CENTER,
  194.                   "Battery: %.0f%%", id(battery_level).state);
  195.       }
  196.      
  197.       // Лічильники кнопок
  198.       int y = 100;
  199.      
  200.       // UP
  201.       it.printf(30, y, id(font_small),
  202.                 id(button_up).state ? Color(0, 255, 0) : Color(100, 100, 100),
  203.                 "UP: %d", id(up_count));
  204.      
  205.       // DOWN
  206.       it.printf(30, y + 30, id(font_small),
  207.                 id(button_down).state ? Color(0, 255, 0) : Color(100, 100, 100),
  208.                 "DOWN: %d", id(down_count));
  209.      
  210.       // LEFT
  211.       it.printf(30, y + 60, id(font_small),
  212.                 id(button_left).state ? Color(0, 255, 0) : Color(100, 100, 100),
  213.                 "LEFT: %d", id(left_count));
  214.      
  215.       // RIGHT
  216.       it.printf(30, y + 90, id(font_small),
  217.                 id(button_right).state ? Color(0, 255, 0) : Color(100, 100, 100),
  218.                 "RIGHT: %d", id(right_count));
  219.      
  220.       // Підказка
  221.       it.print(120, 240, id(font_small), Color(150, 150, 150),
  222.                TextAlign::CENTER, "Press any button");
Advertisement
Add Comment
Please, Sign In to add comment