gobot.io/x/gobot/v2@v2.1.0/doc.go (about) 1 // Copyright 2014-2018 The Hybrid Group. All rights reserved. 2 3 /* 4 Package gobot is the primary entrypoint for Gobot (http://gobot.io), a framework for robotics, physical computing, and the Internet of Things written using the Go programming language . 5 6 It provides a simple, yet powerful way to create solutions that incorporate multiple, different hardware devices at the same time. 7 8 # Classic Gobot 9 10 Here is a "Classic Gobot" program that blinks an LED using an Arduino: 11 12 package main 13 14 import ( 15 "time" 16 17 "gobot.io/x/gobot/v2" 18 "gobot.io/x/gobot/v2/drivers/gpio" 19 "gobot.io/x/gobot/v2/platforms/firmata" 20 ) 21 22 func main() { 23 firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0") 24 led := gpio.NewLedDriver(firmataAdaptor, "13") 25 26 work := func() { 27 gobot.Every(1*time.Second, func() { 28 led.Toggle() 29 }) 30 } 31 32 robot := gobot.NewRobot("bot", 33 []gobot.Connection{firmataAdaptor}, 34 []gobot.Device{led}, 35 work, 36 ) 37 38 robot.Start() 39 } 40 41 # Metal Gobot 42 43 You can also use Metal Gobot and pick and choose from the various Gobot packages to control hardware with nothing but pure idiomatic Golang code. For example: 44 45 package main 46 47 import ( 48 "gobot.io/x/gobot/v2/drivers/gpio" 49 "gobot.io/x/gobot/v2/platforms/intel-iot/edison" 50 "time" 51 ) 52 53 func main() { 54 e := edison.NewAdaptor() 55 e.Connect() 56 57 led := gpio.NewLedDriver(e, "13") 58 led.Start() 59 60 for { 61 led.Toggle() 62 time.Sleep(1000 * time.Millisecond) 63 } 64 } 65 66 # Master Gobot 67 68 Finally, you can use Master Gobot to add the complete Gobot API or control swarms of Robots: 69 70 package main 71 72 import ( 73 "fmt" 74 "time" 75 76 "gobot.io/x/gobot/v2" 77 "gobot.io/x/gobot/v2/api" 78 "gobot.io/x/gobot/v2/platforms/sphero" 79 ) 80 81 func NewSwarmBot(port string) *gobot.Robot { 82 spheroAdaptor := sphero.NewAdaptor(port) 83 spheroDriver := sphero.NewSpheroDriver(spheroAdaptor) 84 spheroDriver.SetName("Sphero" + port) 85 86 work := func() { 87 spheroDriver.Stop() 88 89 spheroDriver.On(sphero.Collision, func(data interface{}) { 90 fmt.Println("Collision Detected!") 91 }) 92 93 gobot.Every(1*time.Second, func() { 94 spheroDriver.Roll(100, uint16(gobot.Rand(360))) 95 }) 96 gobot.Every(3*time.Second, func() { 97 spheroDriver.SetRGB(uint8(gobot.Rand(255)), 98 uint8(gobot.Rand(255)), 99 uint8(gobot.Rand(255)), 100 ) 101 }) 102 } 103 104 robot := gobot.NewRobot("sphero", 105 []gobot.Connection{spheroAdaptor}, 106 []gobot.Device{spheroDriver}, 107 work, 108 ) 109 110 return robot 111 } 112 113 func main() { 114 master := gobot.NewMaster() 115 api.NewAPI(master).Start() 116 117 spheros := []string{ 118 "/dev/rfcomm0", 119 "/dev/rfcomm1", 120 "/dev/rfcomm2", 121 "/dev/rfcomm3", 122 } 123 124 for _, port := range spheros { 125 master.AddRobot(NewSwarmBot(port)) 126 } 127 128 master.Start() 129 } 130 131 Copyright (c) 2013-2018 The Hybrid Group. Licensed under the Apache 2.0 license. 132 */ 133 package gobot // import "gobot.io/x/gobot/v2"