gobot.io/x/gobot/v2@v2.1.0/examples/firmata_aip1640.go (about) 1 //go:build example 2 // +build example 3 4 // 5 // Do not build by default. 6 7 /* 8 How to run 9 Pass serial port to use as the first param: 10 11 go run examples/firmata_aip1640.go /dev/ttyACM0 12 */ 13 14 package main 15 16 import ( 17 "os" 18 "time" 19 20 "gobot.io/x/gobot/v2" 21 "gobot.io/x/gobot/v2/drivers/gpio" 22 "gobot.io/x/gobot/v2/platforms/firmata" 23 ) 24 25 func main() { 26 27 firmataAdaptor := firmata.NewAdaptor(os.Args[1]) 28 // In the WEMOS D1 Mini LED Matrix Shield clockPin = 14, dataPin = 13 29 aip1640 := gpio.NewAIP1640Driver(firmataAdaptor, "14", "13") 30 31 smiles := [3][8]byte{ 32 {0x3C, 0x42, 0xA5, 0x81, 0xA5, 0x99, 0x42, 0x3C}, // happy :) 33 {0x3C, 0x42, 0xA5, 0x81, 0xBD, 0x81, 0x42, 0x3C}, // normal :| 34 {0x3C, 0x42, 0xA5, 0x81, 0x99, 0xA5, 0x42, 0x3C}, // sad :( 35 } 36 37 s := 0 38 work := func() { 39 aip1640.Clear() 40 gobot.Every(600*time.Millisecond, func() { 41 aip1640.DrawMatrix(smiles[s]) 42 aip1640.Display() 43 s++ 44 if s > 2 { 45 s = 0 46 } 47 }) 48 } 49 50 robot := gobot.NewRobot("aip1640Bot", 51 []gobot.Connection{firmataAdaptor}, 52 []gobot.Device{aip1640}, 53 work, 54 ) 55 56 robot.Start() 57 }