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.
digispark: add examples using digispark with i2c devices blinkm and m…
…lp115a2 Signed-off-by: Ron Evans <[email protected]>
- Loading branch information
1 parent
be798fd
commit 0b56060
Showing
2 changed files
with
81 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,41 @@ | ||
// +build example | ||
// | ||
// Do not build by default. | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"gobot.io/x/gobot" | ||
"gobot.io/x/gobot/drivers/i2c" | ||
"gobot.io/x/gobot/platforms/digispark" | ||
) | ||
|
||
func main() { | ||
board := digispark.NewAdaptor() | ||
blinkm := i2c.NewBlinkMDriver(board) | ||
|
||
work := func() { | ||
gobot.Every(3*time.Second, func() { | ||
r := byte(gobot.Rand(255)) | ||
g := byte(gobot.Rand(255)) | ||
b := byte(gobot.Rand(255)) | ||
blinkm.Rgb(r, g, b) | ||
color, _ := blinkm.Color() | ||
fmt.Println("color", color) | ||
}) | ||
} | ||
|
||
robot := gobot.NewRobot("blinkBot", | ||
[]gobot.Connection{board}, | ||
[]gobot.Device{blinkm}, | ||
work, | ||
) | ||
|
||
err := robot.Start() | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
} |
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,40 @@ | ||
// +build example | ||
// | ||
// Do not build by default. | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"gobot.io/x/gobot" | ||
"gobot.io/x/gobot/drivers/i2c" | ||
"gobot.io/x/gobot/platforms/digispark" | ||
) | ||
|
||
func main() { | ||
board := digispark.NewAdaptor() | ||
mpl115a2 := i2c.NewMPL115A2Driver(board) | ||
|
||
work := func() { | ||
gobot.Every(1*time.Second, func() { | ||
press, _ := mpl115a2.Pressure() | ||
fmt.Println("Pressure", press) | ||
|
||
temp, _ := mpl115a2.Temperature() | ||
fmt.Println("Temperature", temp) | ||
}) | ||
} | ||
|
||
robot := gobot.NewRobot("blinkBot", | ||
[]gobot.Connection{board}, | ||
[]gobot.Device{mpl115a2}, | ||
work, | ||
) | ||
|
||
err := robot.Start() | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
} |