|
| 1 | +# go-rpi-rgb-led-matrix [](https://godoc.org/github.com/mcuadros/go-rpi-rgb-led-matrix) [](https://travis-ci.org/mcuadros/go-rpi-rgb-led-matrix) |
| 2 | +<img width="250" src="https://cloud.githubusercontent.com/assets/1573114/20248154/c17c1f2e-a9dd-11e6-805b-bf7d8ee73121.gif" align="right" /> |
| 3 | +Go binding for [`rpi-rgb-led-matrix`](https://github.com/hzeller/rpi-rgb-led-matrix) an excellent C++ library to control [RGB LED displays](https://learn.adafruit.com/32x16-32x32-rgb-led-matrix/overview) with Raspberry Pi GPIO. |
| 4 | + |
| 5 | +This library includes the basic bindings to control de LED Matrix directly and also a convenient [ToolKit](https://godoc.org/github.com/mcuadros/go-rpi-rgb-led-matrix#ToolKit) with more high level functions. Also some [examples](https://github.com/mcuadros/go-rpi-rgb-led-matrix/tree/master/examples) are included to test the library and the configuration. |
| 6 | + |
| 7 | +The [`Canvas`](https://godoc.org/github.com/mcuadros/go-rpi-rgb-led-matrix#Canvas) struct implements the [`image.Image`](https://golang.org/pkg/image/#Image) interface from the Go standard library. This makes the interaction with the matrix simple as work with a normal image in Go, allowing the usage of any Go library build around the `image.Image` interface. |
| 8 | + |
| 9 | +To learn about the configuration and the wiring go to the [original library](https://github.com/hzeller/rpi-rgb-led-matrix), is highly detailed and well explained. |
| 10 | + |
| 11 | +Installation |
| 12 | +------------ |
| 13 | + |
| 14 | +The recommended way to install `go-rpi-rgb-led-matrix` is: |
| 15 | + |
| 16 | +```sh |
| 17 | +go get github.com/mcuadros/go-rpi-rgb-led-matrix |
| 18 | +``` |
| 19 | + |
| 20 | +Then you will get an *expected* error like this: |
| 21 | + |
| 22 | +``` |
| 23 | +# github.com/mcuadros/go-rpi-rgb-led-matrix |
| 24 | +/usr/bin/ld: cannot find -lrgbmatrix |
| 25 | +collect2: error: ld returned 1 exit status |
| 26 | +``` |
| 27 | + |
| 28 | +This happens because you need to have installed the `rgbmatrix` C bindings, execute the following commands to install it: |
| 29 | + |
| 30 | +```sh |
| 31 | +cd $GOPATH/src/github.com/mcuadros/go-rpi-rgb-led-matrix/vendor/rpi-rgb-led-matrix/ |
| 32 | +git submodule update --init |
| 33 | +make install |
| 34 | +cd $GOPATH/src/github.com/mcuadros/go-rpi-rgb-led-matrix/ |
| 35 | +go install -v ./... |
| 36 | +``` |
| 37 | + |
| 38 | +Examples |
| 39 | +-------- |
| 40 | + |
| 41 | +Setting all the pixels to white: |
| 42 | + |
| 43 | +```go |
| 44 | +// create a new Matrix instance with the DefaultConfig |
| 45 | +m, _ := rgbmatrix.NewRGBLedMatrix(&rgbmatrix.DefaultConfig) |
| 46 | + |
| 47 | +// create the Canvas, implements the image.Image interface |
| 48 | +c := rgbmatrix.NewCanvas(m) |
| 49 | +defer c.Close() // don't forgot close the Matrix, if not your leds will remain on |
| 50 | + |
| 51 | +// using the standard draw.Draw function we copy a white image onto the Canvas |
| 52 | +draw.Draw(c, c.Bounds(), &image.Uniform{color.White}, image.ZP, draw.Src) |
| 53 | + |
| 54 | +// don't forget call Render to display the new led status |
| 55 | +c.Render() |
| 56 | +``` |
| 57 | + |
| 58 | +Playing a GIF into your matrix during 30 seconds: |
| 59 | + |
| 60 | +```go |
| 61 | +// create a new Matrix instance with the DefaultConfig |
| 62 | +m, _ := rgbmatrix.NewRGBLedMatrix(&rgbmatrix.DefaultConfig) |
| 63 | + |
| 64 | +// create a ToolKit instance |
| 65 | +tk := rgbmatrix.NewToolKit(m) |
| 66 | +defer tk.Close() // don't forgot close the Matrix, if not your leds will remain on |
| 67 | + |
| 68 | +// open the gif file for reading |
| 69 | +file, _ := os.Open("mario.gif") |
| 70 | + |
| 71 | +// play of the gif using the io.Reader |
| 72 | +close, _ := tk.PlayGIF(f) |
| 73 | +fatal(err) |
| 74 | + |
| 75 | +// we wait 30 seconds and then we stop the playing gif sending a True to the returned chan |
| 76 | +time.Sleep(time.Second * 30) |
| 77 | +close <- true |
| 78 | +``` |
| 79 | + |
| 80 | +Using this the running Mario gif, and three 32x64 pannels, was recorded the image from this readme. |
| 81 | +<img src="https://cloud.githubusercontent.com/assets/1573114/20248173/2e2f97ae-a9de-11e6-95e6-e0548199501d.gif" align="right" width="100" /> |
| 82 | + |
| 83 | +Check the folder [`examples`](https://github.com/mcuadros/go-rpi-rgb-led-matrix/tree/master/examples) folder for more examples |
| 84 | + |
| 85 | +License |
| 86 | +------- |
| 87 | + |
| 88 | +MIT, see [LICENSE](LICENSE) |
0 commit comments