gobot.io/x/gobot@v1.16.0/examples/firmata_gpio_max7219.go (about) 1 // +build example 2 // 3 // Do not build by default. 4 5 /* 6 How to setup 7 This examples requires you to daisy-chain 4 led matrices based on MAX7219. 8 It will turn on one led at a time, from the first led at the first matrix to the last led of the last matrix. 9 10 How to run 11 Pass serial port to use as the first param: 12 13 go run examples/firmata_gpio_max7219.go /dev/ttyACM0 14 */ 15 16 package main 17 18 import ( 19 "os" 20 "time" 21 22 "gobot.io/x/gobot" 23 "gobot.io/x/gobot/drivers/gpio" 24 "gobot.io/x/gobot/platforms/firmata" 25 ) 26 27 func main() { 28 firmataAdaptor := firmata.NewAdaptor(os.Args[1]) 29 max := gpio.NewMAX7219Driver(firmataAdaptor, "11", "10", "9", 4) 30 31 var digit byte = 1 // digit address goes from 0x01 (MAX7219Digit0) to 0x08 (MAX7219Digit8) 32 var bits byte = 1 33 var module uint 34 count := 0 35 36 work := func() { 37 gobot.Every(100*time.Millisecond, func() { 38 max.ClearAll() 39 max.One(module, digit, bits) 40 bits = bits << 1 41 42 count++ 43 if count > 7 { 44 count = 0 45 digit++ 46 bits = 1 47 if digit > 8 { 48 digit = 1 49 module++ 50 if module >= 4 { 51 module = 0 52 count = 0 53 } 54 } 55 } 56 }) 57 } 58 59 robot := gobot.NewRobot("Max7219Bot", 60 []gobot.Connection{esp8266}, 61 []gobot.Device{max}, 62 work, 63 ) 64 65 robot.Start() 66 }