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