gobot.io/x/gobot/v2@v2.1.0/examples/tinkerboard_adafruit1109_lcd_keys.go (about) 1 //go:build example 2 // +build example 3 4 // 5 // Do not build by default. 6 7 package main 8 9 import ( 10 "fmt" 11 "time" 12 13 "gobot.io/x/gobot/v2" 14 "gobot.io/x/gobot/v2/drivers/i2c" 15 "gobot.io/x/gobot/v2/platforms/tinkerboard" 16 ) 17 18 // Wiring 19 // PWR Tinkerboard: 1 (+3.3V, VCC), 2 (+5V), 6, 9, 14, 20 (GND) 20 // I2C1 Tinkerboard: 3 (SDA), 5 (SCL) 21 // PLATE: connected via pin header (pin 1..26) 22 func main() { 23 board := tinkerboard.NewAdaptor() 24 ada := i2c.NewAdafruit1109Driver(board, i2c.WithBus(1)) 25 26 work := func() { 27 // set a custom character 28 smiley := [8]byte{0, 0, 10, 0, 0, 17, 14, 0} 29 ada.CreateChar(0, smiley) 30 31 ada.Clear() 32 ada.SetRGB(true, false, false) 33 ada.Write(" Hello from \n Tinker Board ") 34 // add the custom character at the end of the string 35 ada.Write(string(byte(0))) 36 37 // after 1 sec. activate rotation 38 direction := 1 39 gobot.After(1*time.Second, func() { 40 ada.SetRGB(false, true, false) 41 gobot.Every(400*time.Millisecond, func() { 42 if direction == 1 { 43 ada.ScrollLeft() 44 } 45 if direction == 2 { 46 ada.ScrollRight() 47 } 48 }) 49 }) 50 51 // after 7 sec. activate play with the buttons 52 gobot.After(7*time.Second, func() { 53 direction = 0 54 time.Sleep(1 * time.Second) 55 ada.LeftToRight() 56 ada.Clear() 57 ada.SetRGB(false, false, true) 58 ada.Write("Try the buttons!") 59 60 gobot.Every(500*time.Millisecond, func() { 61 if val, err := ada.SelectButton(); err != nil { 62 fmt.Println(err) 63 } else { 64 if val != 0 { 65 ada.Clear() 66 ada.Write("-Select Button-\nclear the screen") 67 ada.Blink(false) 68 direction = 0 69 } 70 } 71 if val, err := ada.UpButton(); err != nil { 72 fmt.Println(err) 73 } else { 74 if val != 0 { 75 ada.Clear() 76 ada.Write(" -Up Button- \nset RGB to white") 77 ada.Blink(false) 78 ada.SetRGB(true, true, true) 79 direction = 0 80 } 81 } 82 if val, err := ada.DownButton(); err != nil { 83 fmt.Println(err) 84 } else { 85 if val != 0 { 86 ada.Clear() 87 ada.Write(" -Down Button- \nset blink on") 88 ada.Blink(true) 89 direction = 0 90 } 91 } 92 if val, err := ada.LeftButton(); err != nil { 93 fmt.Println(err) 94 } else { 95 if val != 0 { 96 ada.Clear() 97 ada.Write(" -Left Button- \nrotate left") 98 ada.Blink(false) 99 direction = 1 100 } 101 } 102 if val, err := ada.RightButton(); err != nil { 103 fmt.Println(err) 104 } else { 105 if val != 0 { 106 ada.Clear() 107 ada.Write(" -Right Button- \nrotate right") 108 ada.Blink(false) 109 direction = 2 110 } 111 } 112 }) 113 114 }) 115 116 } 117 118 robot := gobot.NewRobot("adaBot", 119 []gobot.Connection{board}, 120 []gobot.Device{ada}, 121 work, 122 ) 123 124 robot.Start() 125 }