dongmie3526
dongmie3526
2019-05-26 14:31

调用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 doushi1996 2年前

    @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.

    点赞 评论 复制链接分享