Go module to control Pimoroni's Pirate Audio LCD and buttons.
Head over to the official Pirate Audio GitHub repository to configure your Raspberry to be able to use this library. You'll need the config.txt
changes mentioned in the README.
The driver package for the 240x240px Pirate Audio display.
Heavily based on the TinyGo driver, modified to work with mainline Go, using periph.io to interface with the Raspberry PI (SPI/GPIO).
Also used the Python driver by Philip Howard as a reference.
// Display a rotated image the display
package main
import (
"fmt"
"image/color"
"log"
"os"
"github.com/rubiojr/go-pirateaudio/display"
)
func main() {
if len(os.Args) < 2 {
fmt.Fprintf(os.Stderr, "Usage: %s <img-path>\n", os.Args[0])
os.Exit(1)
}
dsp, err := display.Init()
if err != nil {
panic(err)
}
defer dsp.Close()
// Set the screen color to white
dsp.FillScreen(color.RGBA{R: 0, G: 0, B: 0, A: 0})
img, err := os.Open(os.Args[1])
if err != nil {
log.Fatal(err)
}
defer img.Close()
// Rotate before pushing pixels, so the image appears rotated
dsp.Rotate(display.ROTATION_180)
dsp.DrawImage(img)
}
package main
import (
"fmt"
"time"
"github.com/rubiojr/go-pirateaudio/buttons"
)
func main() {
buttons.OnButtonAPressed(func() {
fmt.Println("Yo Dawg, A pressed")
})
buttons.OnButtonXPressed(func() {
fmt.Println("Yo Dawg, X pressed")
})
buttons.OnButtonYPressed(func() {
fmt.Println("Yo Dawg, Y pressed")
})
buttons.OnButtonBPressed(func() {
fmt.Println("Yo Dawg, B pressed")
})
for {
time.Sleep(1)
}
}
// Rotate an image pressing the 'A' hardware button
package main
import (
"fmt"
"image/color"
"log"
"os"
"time"
"github.com/rubiojr/go-pirateaudio/buttons"
"github.com/rubiojr/go-pirateaudio/display"
)
func main() {
if len(os.Args) < 2 {
fmt.Fprintf(os.Stderr, "Usage: %s <img-path>\n", os.Args[0])
os.Exit(1)
}
dsp, err := display.Init()
if err != nil {
panic(err)
}
defer dsp.Close()
dsp.FillScreen(color.RGBA{R: 0, G: 0, B: 0, A: 0})
var rotation display.Rotation
rotation = 0
buttons.OnButtonAPressed(func() {
dsp.FillScreen(color.RGBA{R: 0, G: 0, B: 0, A: 0})
// Rotate before pushing pixels, so the image appears rotated
dsp.Rotate(rotation)
img, err := os.Open(os.Args[1])
if err != nil {
log.Fatal(err)
}
defer img.Close()
dsp.DrawImage(img)
rotation++
if rotation > 3 {
rotation = 0
}
})
for {
time.Sleep(1)
}
}
package main
import (
"time"
"github.com/rubiojr/go-pirateaudio/textview"
)
func main() {
opts := textview.DefaultOpts
opts.FGColor = textview.GREEN
tv := textview.NewWithOptions(opts)
tv.Draw("")
time.Sleep(3 * time.Second)
tv.DrawChars("Wake up, Neo...")
time.Sleep(3 * time.Second)
tv.DrawChars("The Matrix has you...")
time.Sleep(3 * time.Second)
tv.DrawChars("Follow the white rabbit.")
}