forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds additional examples for C.H.I.P.
- Loading branch information
1 parent
13d6521
commit bc50d79
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/hybridgroup/gobot" | ||
"github.com/hybridgroup/gobot/platforms/chip" | ||
"github.com/hybridgroup/gobot/platforms/gpio" | ||
) | ||
|
||
func main() { | ||
gbot := gobot.NewGobot() | ||
|
||
chipAdaptor := chip.NewChipAdaptor("chip") | ||
button := gpio.NewButtonDriver(chipAdaptor, "button", "U14_19") | ||
led := gpio.NewLedDriver(chipAdaptor, "led", "U14_20") | ||
|
||
work := func() { | ||
gobot.On(button.Event("push"), func(data interface{}) { | ||
led.On() | ||
}) | ||
|
||
gobot.On(button.Event("release"), func(data interface{}) { | ||
led.Off() | ||
}) | ||
} | ||
|
||
robot := gobot.NewRobot("buttonBot", | ||
[]gobot.Connection{chipAdaptor}, | ||
[]gobot.Device{button, led}, | ||
work, | ||
) | ||
gbot.AddRobot(robot) | ||
gbot.Start() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package main | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/hybridgroup/gobot" | ||
"github.com/hybridgroup/gobot/platforms/i2c" | ||
"github.com/hybridgroup/gobot/platforms/chip" | ||
) | ||
|
||
func main() { | ||
gbot := gobot.NewGobot() | ||
|
||
board := chip.NewChipAdaptor("chip") | ||
screen := i2c.NewGroveLcdDriver(board, "screen") | ||
|
||
work := func() { | ||
screen.Write("hello") | ||
|
||
screen.SetRGB(255, 0, 0) | ||
|
||
gobot.After(5*time.Second, func() { | ||
screen.Clear() | ||
screen.Home() | ||
screen.SetRGB(0, 255, 0) | ||
// set a custom character in the first position | ||
screen.SetCustomChar(0, i2c.CustomLCDChars["smiley"]) | ||
// add the custom character at the end of the string | ||
screen.Write("goodbye\nhave a nice day " + string(byte(0))) | ||
gobot.Every(500*time.Millisecond, func() { | ||
screen.Scroll(false) | ||
}) | ||
}) | ||
|
||
screen.Home() | ||
<-time.After(1 * time.Second) | ||
screen.SetRGB(0, 0, 255) | ||
} | ||
|
||
robot := gobot.NewRobot("screenBot", | ||
[]gobot.Connection{board}, | ||
[]gobot.Device{screen}, | ||
work, | ||
) | ||
|
||
gbot.AddRobot(robot) | ||
|
||
gbot.Start() | ||
} |