Giter VIP home page Giter VIP logo

matrix-lite-go's Introduction

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

matrix-lite-go's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

matrix-lite-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.