github.com/aykevl/tinygo@v0.5.0/src/examples/blinkm/blinkm.go (about)

     1  // Connects to an BlinkM I2C RGB LED.
     2  // http://thingm.com/fileadmin/thingm/downloads/BlinkM_datasheet.pdf
     3  package main
     4  
     5  import (
     6  	"machine"
     7  	"time"
     8  )
     9  
    10  func main() {
    11  	machine.I2C0.Configure(machine.I2CConfig{})
    12  
    13  	// Init BlinkM
    14  	machine.I2C0.WriteRegister(0x09, 'o', nil)
    15  
    16  	version := []byte{0, 0}
    17  	machine.I2C0.ReadRegister(0x09, 'Z', version)
    18  	println("Firmware version:", string(version[0]), string(version[1]))
    19  
    20  	count := 0
    21  	for {
    22  		switch count {
    23  		case 0:
    24  			// Crimson
    25  			machine.I2C0.WriteRegister(0x09, 'n', []byte{0xdc, 0x14, 0x3c})
    26  			count = 1
    27  		case 1:
    28  			// MediumPurple
    29  			machine.I2C0.WriteRegister(0x09, 'n', []byte{0x93, 0x70, 0xdb})
    30  			count = 2
    31  		case 2:
    32  			// MediumSeaGreen
    33  			machine.I2C0.WriteRegister(0x09, 'n', []byte{0x3c, 0xb3, 0x71})
    34  			count = 0
    35  		}
    36  
    37  		time.Sleep(100 * time.Millisecond)
    38  	}
    39  }