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.
i2c: implemented DigitalRead, DigitalWrite, and AnalogRead for GrovePi
Signed-off-by: Ron Evans <[email protected]>
- Loading branch information
1 parent
c9276f4
commit b8d26f0
Showing
5 changed files
with
119 additions
and
11 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
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
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
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,41 @@ | ||
// +build example | ||
// | ||
// Do not build by default. | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"gobot.io/x/gobot" | ||
"gobot.io/x/gobot/drivers/gpio" | ||
"gobot.io/x/gobot/drivers/i2c" | ||
"gobot.io/x/gobot/platforms/raspi" | ||
) | ||
|
||
func main() { | ||
r := raspi.NewAdaptor() | ||
gp := i2c.NewGrovePiDriver(r) | ||
button := gpio.NewButtonDriver(gp, "D3") | ||
led := gpio.NewLedDriver(gp, "D2") | ||
|
||
work := func() { | ||
button.On(gpio.ButtonPush, func(data interface{}) { | ||
fmt.Println("button pressed") | ||
led.On() | ||
}) | ||
|
||
button.On(gpio.ButtonRelease, func(data interface{}) { | ||
fmt.Println("button released") | ||
led.Off() | ||
}) | ||
} | ||
|
||
robot := gobot.NewRobot("buttonBot", | ||
[]gobot.Connection{r}, | ||
[]gobot.Device{gp, button, led}, | ||
work, | ||
) | ||
|
||
robot.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,34 @@ | ||
// +build example | ||
// | ||
// Do not build by default. | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"gobot.io/x/gobot" | ||
"gobot.io/x/gobot/drivers/aio" | ||
"gobot.io/x/gobot/drivers/i2c" | ||
"gobot.io/x/gobot/platforms/raspi" | ||
) | ||
|
||
func main() { | ||
board := raspi.NewAdaptor() | ||
gp := i2c.NewGrovePiDriver(board) | ||
sensor := aio.NewGroveRotaryDriver(gp, "A1") | ||
|
||
work := func() { | ||
sensor.On(aio.Data, func(data interface{}) { | ||
fmt.Println("sensor", data) | ||
}) | ||
} | ||
|
||
robot := gobot.NewRobot("sensorBot", | ||
[]gobot.Connection{board}, | ||
[]gobot.Device{gp, sensor}, | ||
work, | ||
) | ||
|
||
robot.Start() | ||
} |