tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/is31fl3731/main.go (about)

     1  package main
     2  
     3  import (
     4  	"time"
     5  
     6  	"machine"
     7  
     8  	"tinygo.org/x/drivers/is31fl3731"
     9  )
    10  
    11  // I2CAddress -- address of led matrix
    12  var I2CAddress uint8 = is31fl3731.I2C_ADDRESS_74
    13  
    14  func main() {
    15  	bus := machine.I2C0
    16  	err := bus.Configure(machine.I2CConfig{})
    17  	if err != nil {
    18  		println("could not configure I2C:", err)
    19  		return
    20  	}
    21  
    22  	// Create driver for Adafruit 15x7 CharliePlex LED Matrix FeatherWing
    23  	// (CharlieWing): https://www.adafruit.com/product/3163
    24  	ledMatrix := is31fl3731.NewAdafruitCharlieWing15x7(bus, I2CAddress)
    25  
    26  	err = ledMatrix.Configure()
    27  	if err != nil {
    28  		println("could not configure is31fl3731 driver:", err)
    29  		return
    30  	}
    31  
    32  	// Fill the whole matrix on the frame #0 (visible by default)
    33  	ledMatrix.Fill(is31fl3731.FRAME_0, uint8(3))
    34  
    35  	// Draw couple pixels on the frame #1 (not visible yet)
    36  	ledMatrix.DrawPixelXY(is31fl3731.FRAME_1, uint8(0), uint8(0), uint8(10))
    37  	ledMatrix.DrawPixelXY(is31fl3731.FRAME_1, uint8(14), uint8(6), uint8(10))
    38  
    39  	// There are 8 frames available, it's a good idea to draw on an invisible
    40  	// frame and then switch to that frame to reduce flickering. Switch between
    41  	// frame #0 and #1 in a loop to show animation:
    42  	for {
    43  		println("show frame #0...")
    44  		ledMatrix.SetActiveFrame(is31fl3731.FRAME_0)
    45  		time.Sleep(time.Second * 3)
    46  
    47  		println("show frame #1...")
    48  		ledMatrix.SetActiveFrame(is31fl3731.FRAME_1)
    49  		time.Sleep(time.Second * 3)
    50  	}
    51  }