dongmie3526 2019-05-26 14:31
浏览 113
已采纳

调用MakeWS2811()之后,是否可以更改rpi-ws281x-go库中LED的亮度?

I've been playing with a Raspberry Pi and Golang to animate some WS2812 LEDs. I've been using the rpi-ws281x-go (https://github.com/rpi-ws281x/rpi-ws281x-go) library which is a Go wrapper around a C library (https://github.com/jgarff/rpi_ws281x). I'm not extremely familiar with C let alone Go wrappers of C libraries.

I can see that in the C code, I can access and change the brightness of the LEDs which is applied every time the render function is called. However, in the Go wrapper library, I don't see a way to access that variable. I can see that when I call ws2811.MakeWS2811(&opt), I can set the brightness in the opt struct. How can I change that brightness after calling MakeWS2811()?

I know how to apply my own brightness in my own animation functions in Go, but that seems redundant since the C function is going to do the same thing.

  • 写回答

1条回答 默认 最新

  • doushi1996 2019-05-27 01:13
    关注

    @Clifford MakeWS2811(...) does take a pointer, but it looks like it makes a copy of the options in C.

    However the returned instance has a Leds(nChannel) method, giving direct access to set the colours of LEDs. You can reduce the colour value to reduce the brightness (approximately).

    ...
    opt.Channels[0].Brightness = ... original value 0 to 255
    ws, err := MakeWS2811(&opts)
    ...
    
    ws.Leds(0)[0] = 0xff //bright red
    ws.Leds(0)[1] = 0x7f //half as bright
    ws.Render()
    

    Note each time the C lib renders, it still scales the colours you set by the original brightness.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器