Skip to content

Commit

Permalink
digispark: add examples using digispark with i2c devices blinkm and m…
Browse files Browse the repository at this point in the history
…lp115a2

Signed-off-by: Ron Evans <[email protected]>
  • Loading branch information
deadprogram committed Aug 24, 2018
1 parent be798fd commit 0b56060
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
41 changes: 41 additions & 0 deletions examples/digispark_blinkm.go
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)
}
}
40 changes: 40 additions & 0 deletions examples/digispark_mpl115a2.go
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)
}
}

0 comments on commit 0b56060

Please sign in to comment.