Git Product home page Git Product logo

go-pirateaudio's Introduction

Pirate Audio Go Module

Go module to control Pimoroni's Pirate Audio LCD and buttons.

⚠️ Highly Experimental, API subject to change, may set your device on fire ⚠️

gadget.jpg

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.

ST7789

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.

Drawing an Image on the display

// 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)
}

Controlling the hardware buttons (A,B,X,Y)

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)
	}
}

Combining HW buttons and image display

// 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)
	}
}

Drawing text

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.")
}

go-pirateaudio's People

Contributors

rubiojr avatar vwhitteron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.