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.

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

报告相同问题?

悬赏问题

  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来