Giter Club home page Giter Club logo

blink's Introduction

blink

Build Status GoDoc License

blink is a go implementation for controlling ThingM blink(1) USB dual RGB LEDs.

Features

  • Fade to RGB color
  • Set RGB color now
  • Read current RGB color (mk2 devices only)
  • Serverdown tickle/off
  • Play/Pause
  • PlayLoop (mk2 devices only)
  • Playstate readback (mk2 devices only)
  • Set color pattern line
  • read color pattern line
  • Save color patterns (mk2 devices only)
  • Read EEPROM location (mk1 devices only)
  • Write EEPROM location (mk1 devices only)
  • Get version
  • Test command

Installation

Currently blink does only compile on linux and requires libusb-1.0.12 or higher. blink is build on travis using libusb 1.0.20. Refer to the .travis.yml to it can be built on ubuntu. On Fedora 22 you can simply use dnf install libusb-devel.

Use go get to install blink:

go get github.com/fgrosse/blink

You need to have go version 1.4 or higher.

Usage

Simple usage

// connect to a local blink(1) USB device
led, err := blink.New()
if err != nil {
    panic(err)
}

// disable all lights and close the device when you are done
defer led.FadeOutClose()

// fade to a full green in 500ms
d := 500 * time.Millisecond
led.FadeRGB(0, 255, 0, d)
time.Sleep(d)

// store colors for later use
corpBlue := blink.MustParseColor("#3333ff")
led.Fade(corpBlue, d)

// read the current color
color, err := led.Read()
if err != nil {
    panic(err)
}
fmt.Printf("%#v\n", color)

Create sequences to store and playback multiple instructions

d := 500 * time.Millisecond
s := blink.NewSequence().
    Fade(blink.Red, d).
    Fade(blink.Green, d).
    Fade(blink.Blue, d).
    Wait(1 * time.Second).
    Off()

// blocks until s is done
err = s.Play(led)
if err != nil {
    panic(err)
}

Sequences can be run in a loop. You can also loop multiple sections.

firstLoop := blink.NewSequence().
    Fade(blink.Red, 250*time.Millisecond).
    Fade(blink.Blue, 250*time.Millisecond).
    LoopN(2) // loops 2 times

secondLoop := firstLoop.
    Fade(blink.Green, 250*time.Millisecond).
    LoopN(4) // loops 4 times starting at the first fade to red

myBlue := blink.MustParseColor("#6666ff")
entireLoop, c := secondLoop.
    Start(). // instruct the next loop to start at this position
    Set(myBlue, 200 * time.Millisecond).
    Set(myBlue.Multiply(0.8), 200 * time.Millisecond).
    Set(myBlue.Multiply(0.6), 200 * time.Millisecond).
    Set(myBlue.Multiply(0.4), 200 * time.Millisecond).
    Loop() // restarts the sequence until c is closed

go func() {
    // stop the whole loop after ten seconds
    time.Sleep(10 * time.Second)
    close(c)
}()

err = entireLoop.Play(led)

Linux Permissions

You need to have root access when running this program or you will get the following error:

libusb: bad access [code -3]

On linux this problem can easily be fixed by adding the following udev rule:

[root@localhost]# cat /etc/udev/rules.d/10.local.rules
SUBSYSTEMS=="usb", ATTRS{idVendor}=="27b8", ATTRS{idProduct}=="01ed", SYMLINK+="blink1", GROUP="blink1"

Everybody in the blink1 group should now be able to access the device directly. Additionally this rule creates a symlink at /dev/blink1 each time you connect the device. You probably need to reconnect your device so the change will be visible.

Other resources

Contributing

Any contributions are always welcome (use pull requests). Please keep in mind that I might not always be able to respond immediately but I usually try to react within the week โ˜บ.

blink's People

Contributors

fgrosse avatar

Stargazers

 avatar  avatar  avatar

Watchers

 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.