Reputation: 739
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.
Upvotes: 0
Views: 732
Reputation: 7091
@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.
Upvotes: 1