matrix

package module
v0.0.0-...-b8518f0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2019 License: GPL-3.0 Imports: 7 Imported by: 0

README

MATRIX-Lite-Go

GoDoc Go Report Card

MATRIX Lite go is a Golang library that allows users of varying skill levels to easily program their MATRIX Device.

Roadmap

  • Leds
  • Sensors
    • IMU
    • Humidity
    • Pressure
    • UV
  • GPIO
  • Microphones
    • Hal Mics
    • Alsa Mics

Installation

Ensure you have a Raspberry Pi, attached with a MATRIX device, that's flashed with Raspbian.

1. Install MATRIX HAL

https://matrix-io.github.io/matrix-documentation/matrix-hal/getting-started/installation-package/

2. Install Golang & Create A Project

Download the latest version of Golang

sudo apt install golang

3. Create A Project

mkdir myapp
cd myapp
go mod init myapp

4. Install matrix-lite-go

go get -u github.com/matrix-io/matrix-lite-go

Usage

Everloop

package main

import (
	"fmt"
	"time"

	"github.com/matrix-io/matrix-lite-go"
)

func main() {
	m := matrix.Init()

	fmt.Println("This device has", m.Led.Length, "LEDs")

	// A single string or object sets all LEDs
	// Below are different ways of expressing a color (number values are from 0-255)
	m.Led.Set("blue")
	m.Led.Set(matrix.RGBW{0, 0, 10, 0})

	// LEDs off
	m.Led.Set("black")
	m.Led.Set(matrix.RGBW{})

	// Slices & Arrays can set individual LEDs
	m.Led.Set([]interface{}{"red", "", matrix.RGBW{}, "black", matrix.RGBW{G: 255}}) // Slice with different data types
	m.Led.Set([]string{"red", "gold", "black", "purple"}) // Slice of strings
	m.Led.Set([5]string{"red", "gold", "black", "purple"}) // Array of strings

	// Slices & Arrays can simulate motion
	// It's recommended to use Slices so that m.Led.Length can be used
	everloop := make([]matrix.RGBW, m.Led.Length)
	everloop[0] = matrix.RGBW{B: 100}

	for {
		lastLed := everloop[0]
		everloop = everloop[1:]
		everloop = append(everloop, lastLed)

		m.Led.Set(everloop)
		time.Sleep(50 * time.Millisecond)
	}
}

Sensors

package main

import (
	"fmt"	

	"github.com/matrix-io/matrix-lite-go"
)

func main() {
	m := matrix.Init()

	m.Imu.Read()
	m.Uv.Read()
	m.Humidity.Read()
	m.Pressure.Read()

	fmt.Println("IMU: ", m.Imu)
	fmt.Println("UV: ", m.Uv)
	fmt.Println("Humidity: ", m.Humidity)
	fmt.Println("Pressure: ", m.Pressure)
}

GPIO


package main

import (
	"fmt"
	
	"github.com/matrix-io/matrix-lite-go"
)

func main() {
	m := matrix.Init()

	// Read GPIO pin 0 (digital)
	m.Gpio.SetFunction(0, "DIGITAL")
	m.Gpio.SetMode(0, "input")
	fmt.Println(m.Gpio.GetDigital(0))

	// Set GPIO pin 1 (digital)
	m.Gpio.SetFunction(1, "DIGITAL")
	m.Gpio.SetMode(1, "output")
	m.Gpio.SetDigital(1, "ON")

	// Set GPIO pin 2 (PWM)
	m.Gpio.SetFunction(2, "PWM");
	m.Gpio.SetMode(2, "output");
	m.Gpio.SetPWM(2, 25, 50);

	// Set Servo Angle pin 3
	m.Gpio.SetFunction(3, "PWM");
	m.Gpio.SetMode(3, "output");
	m.Gpio.SetServoAngle(3, 90, 0.8);
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Gpio

type Gpio struct{}

Gpio is used as the entrance point to communicate with the MATRIX GPIO Pinout.

func (*Gpio) GetDigital

func (*Gpio) GetDigital(pin int) int

GetDigital Reads a Pin's ON(1) or OFF(0) state (digital)

func (*Gpio) SetDigital

func (*Gpio) SetDigital(pin int, value string)

SetDigital configures a pin to use Digital and output an ON/OFF signal

func (*Gpio) SetFunction

func (*Gpio) SetFunction(pin int, function string)

SetFunction sets the pin to do Digital or PWM

func (*Gpio) SetMode

func (*Gpio) SetMode(pin int, mode string)

SetMode sets the pin to input or output signal (digital)

func (*Gpio) SetPWM

func (*Gpio) SetPWM(pin int, percentage float32, frequency float32)

SetPWM configures a pin to use Pulse Width Modulation

func (*Gpio) SetServoAngle

func (*Gpio) SetServoAngle(pin int, angle float32, minPulseMs float32)

SetServoAngle offers better PWM controls to manipulate a servo. Note: minPulseMs is a minimum pulse width for a PWM wave

type Humidity

type Humidity struct {
	Humidity    float32
	Temperature float32
}

Humidity sensor values

func (*Humidity) Read

func (s *Humidity) Read()

Update Humidity{} values

type Imu

type Imu struct {
	AccelX, AccelY, AccelZ float32
	GyroX, GyroY, GyroZ    float32
	Yaw, Pitch, Roll       float32
	MagX, MagY, MagZ       float32
}

Imu sensor values

func (*Imu) Read

func (s *Imu) Read()

Update Imu{} values

type Led

type Led struct {
	Length int
}

Led is used as the entrance point to communicate with the MATRIX everloop (That big ring of LEDs).

func (*Led) Set

func (led *Led) Set(color interface{}) error

Set parses any string, RGBW{}, or list of the previous types to render the MATRIX everloop

type Matrix

type Matrix struct {
	Led
	Gpio
	Imu
	Uv
	Pressure
	Humidity
}

Matrix is the main object that allows communication with MATRIX HAL

func Init

func Init() Matrix

Init starts the MATRIXIOBus or exits the program if it can't. Every HAL function relies on the bus.

type Pressure

type Pressure struct {
	Altitude    float32
	Pressure    float32
	Temperature float32
}

Pressure sensor values

func (*Pressure) Read

func (s *Pressure) Read()

Update Pressure{} values

type RGBW

type RGBW struct {
	R, G, B, W uint8
}

RGBW represents the colors of a MATRIX LED (0-255)

type Uv

type Uv struct {
	Uv float32
}

Uv sensor values

func (*Uv) Read

func (s *Uv) Read()

Update Uv{} values

Jump to

Keyboard shortcuts

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