Now that go is installed (see Part 1), you can get down to business and start using phidgets. I've written a go phidgets library (currently only InterfaceKit
and IR
phidgets are implemented, open an issue or pull request if you want more) at github.com/samuelkadolph/go/phidgets.
- Enable the full Debian Package Repository
- Update apt
apt-get update
- Install gcc, git, the phidget library, and updated CA certificates
apt-get install build-essential git-core libphidget21-dev ca-certificates -y
- Set
GOPATH
export GOPATH="$HOME/go"
- Install my library
go get github.com/samuelkadolph/go/phidgets
Now let's write a program to open the interface kit on the PhidgetSBC3 and turn an output on. You might want to connect an LED to pin 0 and ground to see it working.
root@phidgetsbc:~# cat hello.go
package main
import (
"github.com/samuelkadolph/go/phidgets"
"log"
"time"
)
func main() {
ifk, err := phidgets.NewInterfaceKit()
if err != nil {
log.Fatalf("%s", err)
}
if err := ifk.Open(phidgets.Any); err != nil {
log.Fatalf("%s", err)
}
if err := ifk.WaitForAttachment(200 * time.Millisecond); err != nil {
log.Fatalf("%s", err)
}
s, err := ifk.Outputs[0].State()
if err != nil {
log.Fatalf("%s", err)
}
if err := ifk.Outputs[0].SetState(!s); err != nil {
log.Fatalf("%s", err)
}
time.Sleep(200 * time.Millisecond)
if s {
log.Printf("Output 1 enabled!")
} else {
log.Printf("Output 1 disabled!")
}
}
root@phidgetsbc:~# go run hello.go
2013/03/24 23:47:28 Output 1 enabled!
root@phidgetsbc:~# go run hello.go
2013/03/24 23:47:39 Output 1 disabled!
And just like that, phidgets in go on the PhidgetSBC3.