Skip to content

Go package for interacting with the "ELK" Bluetooth Low Energy RGB LED Controller

Notifications You must be signed in to change notification settings

FergusInLondon/ELK-BLEDOM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go interactions for the ELK-BLEDOM RGB LED Controller

This repository contains information on the common (and cheap) ELK-BLEDOM Bluetooth Low Energy RGB LED controller, as well as a Go package for interacting with it.

Bluetooth interactions have been reverse engineered from the Android app. See PROTOCOL.md for more information on both the hardware and how it can be controlled.

Example

func main() {
	ctx, cancel := context.WithCancel(context.Background())
	d := device.NewBleDomRGBController(ctx, device.Options{})

	if err := d.Connect(time.Duration(time.Minute)); err != nil {
		panic(err)
	}

	gracefulTermination(cancel, d)

	// Don't terminate until device has been cleanly shutdown
	defer func() {
		fmt.Println("waiting for device disconnection")
		d.Done()
		fmt.Println("device disconnected: terminating app")
	}()

	// Configure state polling; retrieve state every 30 seconds and log
	// it to stdout.
	d.PollState(time.Duration(30)*time.Second, func(state []byte) {
		fmt.Println("recieved latest state from device", state)
	})

	fmt.Println("setting brightness to maximum")
	d.WriteCommand(device.BrightnessCommandFromValue(96)) // 96%

	i := 1
	t := time.NewTimer(time.Second)
	for {
		select {
		case <-ctx.Done():
			fmt.Println("context cancelled: stopping commands")
			t.Stop()
			return
		case <-t.C:
			cmd := commands[i%len(commands)]
			fmt.Println("changing colour: ", cmd.Red, cmd.Green, cmd.Blue)
			d.WriteCommand(cmd)

			i = i + 1
			t.Reset(time.Second)
		}
	}
}

See colours.go.

About

Go package for interacting with the "ELK" Bluetooth Low Energy RGB LED Controller

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published