Update digispark package and examples

This commit is contained in:
Adrian Zankich 2014-05-22 20:13:38 -07:00
parent 93ff0d6844
commit 8eaf55552a
6 changed files with 43 additions and 63 deletions

View File

@ -2,26 +2,19 @@ package main
import (
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/digispark"
"github.com/hybridgroup/gobot/gpio"
"github.com/hybridgroup/gobot/api"
"github.com/hybridgroup/gobot/platforms/digispark"
"github.com/hybridgroup/gobot/platforms/gpio"
)
func main() {
master := gobot.NewMaster()
gobot.StartApi(master)
master := gobot.NewGobot()
api.NewApi(master).Start()
digisparkAdaptor := digispark.NewDigisparkAdaptor()
digisparkAdaptor.Name = "Digispark"
digisparkAdaptor := digispark.NewDigisparkAdaptor("Digispark")
led := gpio.NewLed(digisparkAdaptor, "led", "0")
led := gpio.NewLed(digisparkAdaptor)
led.Name = "led"
led.Pin = "0"
master.Robots = append(master.Robots, &gobot.Robot{
Name: "digispark",
Connections: []gobot.Connection{digisparkAdaptor},
Devices: []gobot.Device{led},
})
master.Start()
gbot.Robots = append(gbot.Robots,
gobot.NewRobot("digispark", []gobot.Connection{digisparkAdaptor}, []gobot.Device{led}, nil))
gbot.Start()
}

View File

@ -2,29 +2,23 @@ package main
import (
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/digispark"
"github.com/hybridgroup/gobot/gpio"
"github.com/hybridgroup/gobot/platforms/digispark"
"github.com/hybridgroup/gobot/platforms/gpio"
"time"
)
func main() {
digisparkAdaptor := digispark.NewDigisparkAdaptor()
digisparkAdaptor.Name = "Digispark"
led := gpio.NewLedDriver(digisparkAdaptor)
led.Name = "led"
led.Pin = "0"
gbot := gobot.NewGobot()
digisparkAdaptor := digispark.NewDigisparkAdaptor("Digispark")
led := gpio.NewLedDriver(digisparkAdaptor, "led", "0")
work := func() {
gobot.Every("0.5s", func() {
gobot.Every(0.5*time.Second, func() {
led.Toggle()
})
}
robot := gobot.Robot{
Connections: []gobot.Connection{digisparkAdaptor},
Devices: []gobot.Device{led},
Work: work,
}
robot.Start()
gbot.Robots = append(gbot.Robots,
gobot.NewRobot("blinkBot", []gobot.Connection{digisparkAdaptor}, []gobot.Device{led}, work))
gbot.Start()
}

View File

@ -2,23 +2,22 @@ package main
import (
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/digispark"
"github.com/hybridgroup/gobot/gpio"
"github.com/hybridgroup/gobot/platforms/digispark"
"github.com/hybridgroup/gobot/platforms/gpio"
"time"
)
func main() {
digisparkAdaptor := digispark.NewDigisparkAdaptor()
digisparkAdaptor.Name = "digispark"
gbot := gobot.NewGobot()
led := gpio.NewLedDriver(digisparkAdaptor)
led.Name = "led"
led.Pin = "0"
digisparkAdaptor := digispark.NewDigisparkAdaptor("digispark")
led := gpio.NewLedDriver(digisparkAdaptor, "led", "0")
work := func() {
brightness := uint8(0)
fade_amount := uint8(15)
gobot.Every("0.1s", func() {
gobot.Every(0.1*time.Second, func() {
led.Brightness(brightness)
brightness = brightness + fade_amount
if brightness == 0 || brightness == 255 {
@ -27,11 +26,7 @@ func main() {
})
}
robot := gobot.Robot{
Connections: []gobot.Connection{digisparkAdaptor},
Devices: []gobot.Device{led},
Work: work,
}
robot.Start()
gbot.Robots = append(gbot.Robots,
gobot.NewRobot("pwmBot", []gobot.Connection{digisparkAdaptor}, []gobot.Device{led}, work))
gbot.Start()
}

View File

@ -5,29 +5,24 @@ import (
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/digispark"
"github.com/hybridgroup/gobot/gpio"
"time"
)
func main() {
digisparkAdaptor := digispark.NewDigisparkAdaptor()
digisparkAdaptor.Name = "digispark"
gbot := gobot.NewGobot()
digisparkAdaptor := digispark.NewDigisparkAdaptor("digispark")
servo := gpio.NewServoDriver(digisparkAdaptor)
servo.Name = "servo"
servo.Pin = "0"
servo := gpio.NewServoDriver(digisparkAdaptor, "servo", "0")
work := func() {
gobot.Every("1s", func() {
gobot.Every(1*time.Second, func() {
i := uint8(gobot.Rand(180))
fmt.Println("Turning", i)
servo.Move(i)
})
}
robot := gobot.Robot{
Connections: []gobot.Connection{digisparkAdaptor},
Devices: []gobot.Device{servo},
Work: work,
}
robot.Start()
gbot.Robots = append(gbot.Robots,
gobot.NewRobot("servoBot", []gobot.Connection{digisparkAdaptor}, []gobot.Device{servo}, work))
gbot.Start()
}

View File

@ -13,8 +13,11 @@ type DigisparkAdaptor struct {
connect func(*DigisparkAdaptor)
}
func NewDigisparkAdaptor() *DigisparkAdaptor {
func NewDigisparkAdaptor(name string) *DigisparkAdaptor {
return &DigisparkAdaptor{
Adaptor: gobot.Adaptor{
Name: name,
},
connect: func(d *DigisparkAdaptor) {
d.littleWire = LittleWireConnect()
},

View File

@ -11,7 +11,7 @@ var _ = Describe("Digispark", func() {
)
BeforeEach(func() {
d = NewDigisparkAdaptor()
d = NewDigisparkAdaptor("bot")
d.connect = func(d *DigisparkAdaptor) {}
})