nene1234

lilka simple menu navigation

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