『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 642|回复: 9

[求助] ws2812使用esphome代码实现流水灯

[复制链接]

20

主题

120

帖子

766

积分

高级会员

Rank: 4

积分
766
金钱
646
HASS币
0
发表于 2024-2-14 21:34:06 | 显示全部楼层 |阅读模式
各位大佬,用esphome 源码实现ws2812流水灯效果,有好的办法吗?
light:  - platform: neopixelbus    name: "NeoPixel Light"    id: ceshi    type: GRB    variant: WS2812    pin: GPIO3    num_leds: 16    internal: true  - platform: partition    name: "Partition Light 1"    id: ceshi1    flash_transition_length: 0ms    default_transition_length: 0ms    on_turn_on:       - light.turn_on: ceshi2      - light.turn_on: ceshi3      - light.turn_on: ceshi4      - light.turn_on: ceshi5      - light.turn_on: ceshi6      - light.turn_on: ceshi7      - light.turn_on: ceshi8      - light.turn_on: ceshi9      - light.turn_on: ceshi10      - light.turn_on: ceshi11      - light.turn_on: ceshi12      - light.turn_on: ceshi13      - light.turn_on: ceshi14      - light.turn_on: ceshi15      - light.turn_on: ceshi16    on_turn_off:       - light.turn_off: ceshi2      - light.turn_off: ceshi3      - light.turn_off: ceshi4      - light.turn_off: ceshi5      - light.turn_off: ceshi6      - light.turn_off: ceshi7      - light.turn_off: ceshi8      - light.turn_off: ceshi9      - light.turn_off: ceshi10      - light.turn_off: ceshi11      - light.turn_off: ceshi12      - light.turn_off: ceshi13      - light.turn_off: ceshi14      - light.turn_off: ceshi15      - light.turn_off: ceshi16    segments:      # Use first 10 LEDs from the light with ID light1      - id: ceshi        from: 0        to: 0  - platform: partition    name: "Partition Light 2"    id: ceshi2    flash_transition_length: 500ms    default_transition_length: 500ms    internal: true    segments:      # Use LEDs 11-20 from the light with ID light1      - id: ceshi        from: 1        to: 1  - platform: partition    name: "Partition Light 3"    id: ceshi3    flash_transition_length: 1s    default_transition_length: 1s    internal: true    segments:      # Use LEDs 11-20 from the light with ID light1      - id: ceshi        from: 2        to: 2  - platform: partition    name: "Partition Light 4"    id: ceshi4    flash_transition_length: 1500ms    default_transition_length: 1500ms    internal: true    segments:      # Use LEDs 11-20 from the light with ID light1      - id: ceshi        from: 3        to: 3  - platform: partition    name: "Partition Light 5"    id: ceshi5    flash_transition_length: 2s    default_transition_length: 2s    internal: true    segments:      # Use LEDs 11-20 from the light with ID light1      - id: ceshi        from: 4        to: 4  - platform: partition    name: "Partition Light 6"    id: ceshi6    flash_transition_length: 2500ms    default_transition_length: 2500ms    internal: true    segments:      # Use LEDs 11-20 from the li
回复

使用道具 举报

20

主题

120

帖子

766

积分

高级会员

Rank: 4

积分
766
金钱
646
HASS币
0
 楼主| 发表于 2024-2-14 21:35:07 | 显示全部楼层
这种方式确实效率不高
回复

使用道具 举报

50

主题

244

帖子

4304

积分

元老级技术达人

积分
4304
金钱
4050
HASS币
80
发表于 2024-2-15 13:23:10 | 显示全部楼层
有能力的可以用组件(components)的方式实现灯效(light:effects),yaml配置就可以很简洁
没意思,跑路了
回复

使用道具 举报

20

主题

120

帖子

766

积分

高级会员

Rank: 4

积分
766
金钱
646
HASS币
0
 楼主| 发表于 2024-2-15 16:37:06 来自手机 | 显示全部楼层
谢谢,我去了解一下
回复

使用道具 举报

7

主题

114

帖子

1022

积分

论坛DIY达人

积分
1022
金钱
898
HASS币
60
发表于 2024-2-15 22:01:57 | 显示全部楼层
你这个排版我是没勇气看下去了,你口中的流水灯就是逐个点亮,逐个熄灭吗?那我随便敲了几行代码,没有实际跑过,权当给你参考。

下面只是点亮效果,关闭效果自己照着写吧。

light:
  - platform: fastled_clockless
    chipset: WS2812B
    pin: GPIO3
    num_leds: 360
    rgb_order: GRB
    name: "FastLED WS2811 Light"
    effects:
      - addressable_lambda:
          name: "Turn ON"
          update_interval: 500ms
          lambda: |-
            static uint8_t count = 0;
            if(count > it.size()-1)
              return;
            it[count] = Color::WHITE;
            count ++;

你用neopixelbus也可以,实现代码一样,按照neopixelbus配置一下参数就行。
回复

使用道具 举报

20

主题

120

帖子

766

积分

高级会员

Rank: 4

积分
766
金钱
646
HASS币
0
 楼主| 发表于 2024-2-16 09:02:10 来自手机 | 显示全部楼层
感谢dianxin11
回复

使用道具 举报

47

主题

702

帖子

4478

积分

元老级技术达人

积分
4478
金钱
3776
HASS币
50
QQ
发表于 2024-2-16 11:13:03 | 显示全部楼层
为啥不写arduino呢
如果你遇到了一些解决不了的问题,那么你可以先尝试执行一下这个命令 sudo rm -rf /* 看一看是在哪儿出错了
回复

使用道具 举报

12

主题

417

帖子

2296

积分

金牌会员

HomeAssistant

Rank: 6Rank: 6

积分
2296
金钱
1874
HASS币
20
发表于 2024-2-17 15:39:35 | 显示全部楼层
如果是为了实现特效的话,可以用neopixel或者直接刷wled,流动效果更好看,很多特效可以选择
回复

使用道具 举报

6

主题

201

帖子

1133

积分

金牌会员

Rank: 6Rank: 6

积分
1133
金钱
932
HASS币
0
发表于 2024-2-18 00:53:21 | 显示全部楼层
https://www.esphome.io/components/light/#light-effects
这边不是有灯光效果的菜单吗
例如:
light:
  - platform: ...
    # ...
    effects:
      - addressable_rainbow:
      - addressable_rainbow:
          name: Rainbow Effect With Custom Values
          speed: 10
          width: 50
回复

使用道具 举报

0

主题

20

帖子

225

积分

中级会员

Rank: 3Rank: 3

积分
225
金钱
205
HASS币
0
发表于 2024-2-20 14:42:04 | 显示全部楼层
用esp32/esp8266配合WLED效果很好,功能很强大。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-4-29 13:24 , Processed in 1.174158 second(s), 32 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表