Giter VIP home page Giter VIP logo

scrollphat-go's Introduction

Go library for Pimoroni Scroll pHat

Go library for controlling Pimoroni's Scroll pHat.

Most of the codes were inspired by scroll-phat and Dave Cheney's i2c.

Install

$ go get -u github.com/meinside/scrollphat-go

Configuration

You need to enable I2C first:

$ sudo raspi-config

Also, your account should be in 'i2c' group:

$ sudo usermod -G i2c USERNAME

Sample

// sample.go - sample application for Scroll pHat, 2016.01.07.
package main

import (
	"time"

	scroll "github.com/meinside/scrollphat-go"
)

func main() {
	//scroll.TrimRedundantSpaces = false	// don't trim redundant spaces

	if phat := scroll.New(); phat != nil {
		// set brightneess
		phat.SetBrightness(5)
		time.Sleep(1 * time.Second)

		// turn on all LEDs
		phat.Fill()
		time.Sleep(1 * time.Second)

		// turn off all LEDs
		phat.Clear()
		time.Sleep(1 * time.Second)

		// draw a string (not scrolling)
		phat.DrawBytes(scroll.BytesForString(":-)"))
		time.Sleep(1 * time.Second)

		// draw a string (scrolling)
		phat.Scroll(" 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz `~!@#$%^&*()-=_+[]{};:\"'<>,.?/\\|", 50)
		time.Sleep(1 * time.Second)

		// draw points (heart-shaped...)
		phat.DrawBytes(scroll.ArraysToBytes([][]uint8{
			{0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0},
			{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
			{0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
			{0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
			{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
		}))
		time.Sleep(1 * time.Second)

		// invert LEDs
		phat.Invert()
		time.Sleep(1 * time.Second)

		// turn off all LEDs
		phat.Clear()

		phat.Close()
	} else {
		panic("could not initialize ScrollPHat")
	}
}

Compile it and run like this:

$ go build sample.go
$ ./sample

Then you'll see:

scroll_phat_sample.gif

License

MIT

scrollphat-go's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

dqle

scrollphat-go's Issues

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.