nene1234

lilka simple menu navigation

Nov 16th, 2025 (edited)
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 5.84 KB | None | 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. wifi:
  16.   ssid: !secret wifi_ssid
  17.   password: !secret wifi_password
  18.   ap:
  19.     ssid: "Lilka Fallback Hotspot"
  20.     password: "hnYImYM4O6I0"
  21.  
  22. captive_portal:
  23.  
  24. web_server:
  25.   port: 80
  26.  
  27. api:
  28.   encryption:
  29.     key: "Yw3yq8lxsaze+jdggjAwxKpV4GD6gNZptvw4d6OPfOc="
  30.  
  31. logger:
  32. ota:
  33.   - platform: esphome
  34.     password: "bb198feb99159fdaefc8092f10039acd"
  35.  
  36. output:
  37.   - platform: gpio
  38.     pin: 46
  39.     id: display_power
  40.     inverted: false
  41.  
  42. sensor:
  43.   - platform: adc
  44.     pin: GPIO3
  45.     name: "Battery Voltage"
  46.     id: battery_voltage
  47.     update_interval: 10s
  48.     attenuation: 12db
  49.     filters:
  50.       - multiply: 1.33
  51.    
  52.   - platform: template
  53.     name: "Battery Level"
  54.     id: battery_level
  55.     unit_of_measurement: "%"
  56.     accuracy_decimals: 0
  57.     update_interval: 10s
  58.     lambda: |-
  59.       float voltage = id(battery_voltage).state;
  60.       float percent = (voltage - 3.0) / (4.2 - 3.0) * 100.0;
  61.       if (percent > 100) percent = 100;
  62.       if (percent < 0) percent = 0;
  63.       return percent;
  64.  
  65. spi:
  66.   clk_pin: 18
  67.   mosi_pin: 17
  68.  
  69. display:
  70.   - platform: mipi_spi
  71.     model: ST7789V
  72.     id: my_display
  73.     dc_pin: 15
  74.     cs_pin: 7
  75.     update_interval: 1s
  76.     rotation: 270
  77.     invert_colors: true
  78.     color_order: BGR
  79.     pixel_mode: 16bit
  80.     dimensions:
  81.       width: 280
  82.       height: 240
  83.       offset_width: 20
  84.       offset_height: 0
  85.     auto_clear_enabled: false
  86.  
  87. lvgl:
  88.   log_level: INFO
  89.   style_definitions:
  90.     - id: default_style
  91.       bg_color: 0x000000
  92.       text_color: 0xFFFFFF
  93.     - id: focused_style
  94.       border_color: 0xFFFFFF
  95.       border_width: 3
  96.   pages:
  97.     - id: main_page
  98.       bg_color: 0x000000
  99.       widgets:
  100.         - button:
  101.             id: red_button
  102.             align: CENTER
  103.             y: -40
  104.             width: 180
  105.             height: 50
  106.             bg_color: 0xFF0000
  107.             widgets:
  108.               - label:
  109.                   id: battery_label
  110.                   text: "Battery: --"
  111.                   align: CENTER
  112.         - button:
  113.             id: green_button
  114.             align: CENTER
  115.             y: 20
  116.             width: 180
  117.             height: 50
  118.             bg_color: 0x00FF00
  119.             widgets:
  120.               - label:
  121.                   id: voltage_label
  122.                   text: "Voltage: --"
  123.                   align: CENTER
  124.                   text_color: 0x000000
  125.         - button:
  126.             id: blue_button
  127.             align: CENTER
  128.             y: 80
  129.             width: 180
  130.             height: 50
  131.             bg_color: 0x0000FF
  132.             widgets:
  133.               - label:
  134.                   text: "Lilka LVGL"
  135.                   align: CENTER
  136.                   text_color: 0xFFFFFF
  137.  
  138. globals:
  139.   - id: current_button_index
  140.     type: int
  141.     restore_value: no
  142.     initial_value: '0'
  143.  
  144. script:
  145.   - id: update_focus
  146.     then:
  147.       - lvgl.widget.update:
  148.           id: red_button
  149.           border_width: !lambda 'return id(current_button_index) == 0 ? 3 : 0;'
  150.       - lvgl.widget.update:
  151.           id: green_button
  152.           border_width: !lambda 'return id(current_button_index) == 1 ? 3 : 0;'
  153.       - lvgl.widget.update:
  154.           id: blue_button
  155.           border_width: !lambda 'return id(current_button_index) == 2 ? 3 : 0;'
  156.  
  157. binary_sensor:
  158.   - platform: gpio
  159.     pin:
  160.       number: 38
  161.       mode: INPUT_PULLUP
  162.       inverted: true
  163.     id: button_up
  164.     filters:
  165.       - delayed_on_off: 50ms
  166.     on_press:
  167.       - lambda: |-
  168.           id(current_button_index)--;
  169.           if (id(current_button_index) < 0) id(current_button_index) = 2;
  170.       - script.execute: update_focus
  171.  
  172.   - platform: gpio
  173.     pin:
  174.       number: 41
  175.       mode: INPUT_PULLUP
  176.       inverted: true
  177.     id: button_down
  178.     filters:
  179.       - delayed_on_off: 50ms
  180.     on_press:
  181.       - lambda: |-
  182.           id(current_button_index)++;
  183.           if (id(current_button_index) > 2) id(current_button_index) = 0;
  184.       - script.execute: update_focus
  185.  
  186.   - platform: gpio
  187.     pin:
  188.       number: 39
  189.       mode: INPUT_PULLUP
  190.       inverted: true
  191.     id: button_left
  192.     filters:
  193.       - delayed_on_off: 50ms
  194.  
  195.   - platform: gpio
  196.     pin:
  197.       number: 40
  198.       mode: INPUT_PULLUP
  199.       inverted: true
  200.     id: button_right
  201.     filters:
  202.       - delayed_on_off: 50ms
  203.  
  204.   - platform: gpio
  205.     pin:
  206.       number: 5
  207.       mode: INPUT_PULLUP
  208.       inverted: true
  209.     id: button_a
  210.     filters:
  211.       - delayed_on_off: 50ms
  212.  
  213.   - platform: gpio
  214.     pin:
  215.       number: 6
  216.       mode: INPUT_PULLUP
  217.       inverted: true
  218.     id: button_b
  219.     filters:
  220.       - delayed_on_off: 50ms
  221.  
  222.   - platform: gpio
  223.     pin:
  224.       number: 10
  225.       mode: INPUT_PULLUP
  226.       inverted: true
  227.     id: button_c
  228.     filters:
  229.       - delayed_on_off: 50ms
  230.  
  231.   - platform: gpio
  232.     pin:
  233.       number: 9
  234.       mode: INPUT_PULLUP
  235.       inverted: true
  236.     id: button_d
  237.     filters:
  238.       - delayed_on_off: 50ms
  239.  
  240.   - platform: gpio
  241.     pin:
  242.       number: 4
  243.       mode: INPUT_PULLUP
  244.       inverted: true
  245.     id: button_start
  246.     filters:
  247.       - delayed_on_off: 50ms
  248.  
  249.   - platform: gpio
  250.     pin:
  251.       number: 0
  252.       mode: INPUT_PULLUP
  253.       inverted: true
  254.     id: button_select
  255.     filters:
  256.       - delayed_on_off: 50ms
  257.  
  258. interval:
  259.   - interval: 5s
  260.     then:
  261.       - lvgl.label.update:
  262.           id: battery_label
  263.           text: !lambda |-
  264.             return std::string("Battery: ") + to_string((int)id(battery_level).state) + "%";
  265.       - lvgl.label.update:
  266.           id: voltage_label
  267.           text: !lambda |-
  268.             char buf[20];
  269.             snprintf(buf, sizeof(buf), "Voltage: %.2fV", id(battery_voltage).state);
  270.             return std::string(buf);
Advertisement
Add Comment
Please, Sign In to add comment