/
main.go
51 lines (43 loc) · 1.21 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"fmt"
// "time"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/firmata"
"github.com/hybridgroup/gobot/platforms/gpio"
"github.com/ChimeraCoder/anaconda"
"strings"
"strconv"
)
func main() {
gbot := gobot.NewGobot()
firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "COM3")
servo := gpio.NewServoDriver(firmataAdaptor, "servo", "9")
fmt.Println("Hello Twitter, 世界")
anaconda.SetConsumerKey("bsYrbbtqg9l2u2hYhgz76h6ux")
anaconda.SetConsumerSecret("urcJNRZ9qZeCUQfqEoZ0e4Q5JMUmbDgn5bRtbWN0lTyhkgvkPx")
api := anaconda.NewTwitterApi("3145150396-22DQi9gphmz3XX30Y6jCAmKrWvzjaldIQFybqry", "oEOcLxm8uo8V7jSm3IKNq44jcgS66zhikIbgEg4r0l4UT")
stream := api.UserStream(nil)
work := func() {
for {
channel := <-stream.C
t, ok := channel.(anaconda.Tweet)
if !ok {
fmt.Println("Recieved non tweet message")
}
if(strings.Contains(t.Text,"#turn")){
degree := strings.Split(t.Text,"#turn")[1]
x,_ := strconv.ParseUint(degree,10,8)
fmt.Println("Turning ",x)
servo.Move(uint8(x))
}
}
}
robot := gobot.NewRobot("servoBot",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{servo},
work,
)
gbot.AddRobot(robot)
gbot.Start()
}