ssd1306

package
v0.0.0-...-f66468e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2017 License: MIT Imports: 5 Imported by: 0

README

ssd1306

Examples

Adafruit 128x64 OLED Bonnet for Raspberry Pi

https://www.adafruit.com/product/3531

package main

import (
	"fmt"
	"image"
	"log"
	"time"

	"github.com/fogleman/gg"
	"github.com/mikegleasonjr/devices/ssd1306/adafruit/bonnet"
)

func main() {
	b, err := bonnet.New("", false)
	if err != nil {
		log.Fatal(err)
	}
	defer b.Close(true)

	t := time.NewTicker(time.Second)
	defer t.Stop()

	ctx := gg.NewContext(b.Bounds().Dx(), b.Bounds().Dy())

	for {
		select {
		case <-t.C:
			ctx.SetRGB(0, 0, 0)
			ctx.Clear()
			ctx.SetRGB(1, 1, 1)
			ctx.DrawStringAnchored(time.Now().Format("15:04:05"), 0, 0, 0, 1)
			b.Draw(b.Bounds(), ctx.Image(), image.ZP)
		case e := <-b.Events:
			fmt.Println("button", e.Button, "pressed:", e.Pressed)
			if e.Button == bonnet.C {
				return
			}
		}
	}
}
Adafruit PiOLED - 128x32 Monochrome OLED Add-on for Raspberry Pi

https://www.adafruit.com/product/3527

package main

import (
	"image"
	"log"
	"os"
	"os/signal"
	"time"

	"github.com/fogleman/gg"
	"github.com/mikegleasonjr/devices/ssd1306/adafruit/pioled"
)

func main() {
	p, err := pioled.New("", false)
	if err != nil {
		log.Fatal(err)
	}
	defer p.Close(true)

	t := time.NewTicker(time.Second)
	defer t.Stop()

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)

	ctx := gg.NewContext(p.Bounds().Dx(), p.Bounds().Dy())

	for {
		select {
		case <-t.C:
			ctx.SetRGB(0, 0, 0)
			ctx.Clear()
			ctx.SetRGB(1, 1, 1)
			ctx.DrawStringAnchored(time.Now().Format("15:04:05"), 0, 0, 0, 1)
			p.Draw(p.Bounds(), ctx.Image(), image.ZP)
		case <-c:
			return
		}
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type I2C

type I2C struct {
	*ssd1306.Dev
	// contains filtered or unexported fields
}

I2C is an OLED display with hardware I2C.

func NewI2C

func NewI2C(name string, width, height int, rotated bool) (*I2C, error)

NewI2C creates an OLED display

func (*I2C) Close

func (s *I2C) Close(turnoff bool)

Close closes the display

func (*I2C) Tx

func (s *I2C) Tx(w []byte) error

Tx sends raw commands to the displays

Directories

Path Synopsis
adafruit

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL