本文整理汇总了Golang中github.com/kidoman/embd.NewDigitalPin函数的典型用法代码示例。如果您正苦于以下问题:Golang NewDigitalPin函数的具体用法?Golang NewDigitalPin怎么用?Golang NewDigitalPin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewDigitalPin函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: OpenDigits
func OpenDigits() (*Digits, error) {
mosiPin, err := embd.NewDigitalPin(10)
if err != nil {
return nil, err
}
clkPin, err := embd.NewDigitalPin(11)
if err != nil {
return nil, err
}
csPin, err := embd.NewDigitalPin(8)
if err != nil {
return nil, err
}
if err := mosiPin.SetDirection(embd.Out); err != nil {
panic(err)
}
if err := clkPin.SetDirection(embd.Out); err != nil {
panic(err)
}
if err := csPin.SetDirection(embd.Out); err != nil {
panic(err)
}
return &Digits{
mosiPin: mosiPin,
clkPin: clkPin,
csPin: csPin,
}, nil
}
示例2: main
func main() {
if err := embd.InitGPIO(); err != nil {
panic(err)
}
defer embd.CloseGPIO()
echoPin, err := embd.NewDigitalPin(10)
if err != nil {
panic(err)
}
triggerPin, err := embd.NewDigitalPin(9)
if err != nil {
panic(err)
}
rf := us020.New(echoPin, triggerPin, nil)
defer rf.Close()
for {
distance, err := rf.Distance()
if err != nil {
panic(err)
}
fmt.Printf("Distance is %v\n", distance)
time.Sleep(500 * time.Millisecond)
}
}
示例3: OpenLights
func OpenLights() (*Lights, error) {
redPin, err := embd.NewDigitalPin(2)
if err != nil {
return nil, err
}
yellowPin, err := embd.NewDigitalPin(3)
if err != nil {
return nil, err
}
greenPin, err := embd.NewDigitalPin(4)
if err != nil {
return nil, err
}
if err := redPin.SetDirection(embd.Out); err != nil {
panic(err)
}
if err := yellowPin.SetDirection(embd.Out); err != nil {
panic(err)
}
if err := greenPin.SetDirection(embd.Out); err != nil {
panic(err)
}
l := &Lights{
redPin: redPin,
yellowPin: yellowPin,
greenPin: greenPin,
}
return l, nil
}
示例4: main
func main() {
flag.Parse()
if err := embd.InitGPIO(); err != nil {
panic(err)
}
defer embd.CloseGPIO()
pin, err := embd.NewDigitalPin(7)
if err != nil {
panic(err)
}
defer pin.Close()
fluidSensor := watersensor.New(pin)
for {
wet, err := fluidSensor.IsWet()
if err != nil {
panic(err)
}
if wet {
glog.Info("bot is dry")
} else {
glog.Info("bot is Wet")
}
time.Sleep(500 * time.Millisecond)
}
}
示例5: main
func main() {
flag.Parse()
if err := embd.InitGPIO(); err != nil {
panic(err)
}
defer embd.CloseGPIO()
led, err := embd.NewDigitalPin(10)
if err != nil {
panic(err)
}
defer led.Close()
if err := led.SetDirection(embd.Out); err != nil {
panic(err)
}
if err := led.Write(embd.High); err != nil {
panic(err)
}
time.Sleep(1 * time.Second)
if err := led.SetDirection(embd.In); err != nil {
panic(err)
}
}
示例6: main
func main() {
flag.Parse()
if err := embd.InitGPIO(); err != nil {
panic(err)
}
defer embd.CloseGPIO()
btn, err := embd.NewDigitalPin(10)
if err != nil {
panic(err)
}
defer btn.Close()
if err := btn.SetDirection(embd.In); err != nil {
panic(err)
}
btn.ActiveLow(false)
quit := make(chan interface{})
err = btn.Watch(embd.EdgeFalling, func(btn embd.DigitalPin) {
quit <- btn
})
if err != nil {
panic(err)
}
fmt.Printf("Button %v was pressed.\n", <-quit)
}
示例7: newButtons
func newButtons() Buttons {
btns := &buttons{
clicks: map[string]int{"0": 0, "1": 0, "2": 0},
gpioBtns: []*gpioButton{},
}
for i := 0; i < 3; i++ {
btnNum := i
pinNumber := 22 + i
log.Println("Set up", btnNum+1, "at pin", pinNumber)
pin, err := embd.NewDigitalPin(pinNumber)
if err != nil {
fmt.Printf("Error in NewDigitalPin (%d)!", pinNumber)
panic(err)
}
if err := pin.SetDirection(embd.In); err != nil {
fmt.Printf("Error in SetDirection (%d)!", pinNumber)
panic(err)
}
gpioBtn := &gpioButton{number: fmt.Sprintf("%d", btnNum), pin: pin}
btns.gpioBtns = append(btns.gpioBtns, gpioBtn)
}
return btns
}
示例8: New
func New(pin int) *LED {
p, err := embd.NewDigitalPin(pin)
if err != nil {
fmt.Fprintf(os.Stderr, "error instantiating pin %v: %s\n", pin, err)
os.Exit(1)
}
p.SetDirection(embd.Out)
return &LED{pin: p}
}
示例9: inputPin
func inputPin(n int) embd.DigitalPin {
pin, err := embd.NewDigitalPin(n)
if err != nil {
panic(err)
}
pin.SetDirection(embd.In)
return pin
}
示例10: outputPin
func outputPin(n int, value int) embd.DigitalPin {
pin, err := embd.NewDigitalPin(n)
if err != nil {
panic(err)
}
pin.SetDirection(embd.Out)
pin.Write(value)
return pin
}
示例11: main
func main() {
flag.Parse()
if err := embd.InitGPIO(); err != nil {
panic(err)
}
defer embd.CloseGPIO()
data, err := embd.NewDigitalPin(4)
if err != nil {
panic(err)
}
defer data.Close()
clock, err := embd.NewDigitalPin(3)
if err != nil {
panic(err)
}
defer clock.Close()
sensor := sht1x.New(data, clock)
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt, os.Kill)
defer signal.Stop(quit)
ticker := time.NewTicker(2 * time.Second)
defer ticker.Stop()
for {
select {
case <-ticker.C:
m, err := sensor.Measure()
if err != nil {
fmt.Printf("err: %v\n", err)
}
fmt.Printf("Temperature: %.1fC, Relative Humidity: %.1f%%, Dew Point: %.1fC\n", m.Temperature, m.RelativeHumidity, m.DewPoint)
case <-quit:
return
}
}
}
示例12: InitGPIO
func InitGPIO(file string) (embd.DigitalPin, error) {
embd.InitGPIO()
pin, pin_err := embd.NewDigitalPin(file)
if pin_err != nil {
log.Fatal("Error opening pin! \n", pin_err)
return nil, pin_err
}
pin.SetDirection(embd.In)
return pin, nil
}
示例13: main
func main() {
flag.Parse()
if err := embd.InitGPIO(); err != nil {
panic(err)
}
defer embd.CloseGPIO()
echoPin, err := embd.NewDigitalPin("P9_21")
if err != nil {
panic(err)
}
triggerPin, err := embd.NewDigitalPin("P9_22")
if err != nil {
panic(err)
}
rf := us020.New(echoPin, triggerPin, nil)
defer rf.Close()
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt, os.Kill)
for {
select {
default:
distance, err := rf.Distance()
if err != nil {
panic(err)
}
fmt.Printf("Distance is %v\n", distance)
time.Sleep(500 * time.Millisecond)
case <-quit:
return
}
}
}
示例14: New
// New creates a new interface for matrix4x3.
func New(rowPins, colPins []int) (*Matrix4x3, error) {
m := &Matrix4x3{
rowPins: make([]embd.DigitalPin, rows),
colPins: make([]embd.DigitalPin, cols),
poll: pollDelay,
}
var err error
for i := 0; i < rows; i++ {
m.rowPins[i], err = embd.NewDigitalPin(rowPins[i])
if err != nil {
return nil, err
}
}
for i := 0; i < cols; i++ {
m.colPins[i], err = embd.NewDigitalPin(colPins[i])
if err != nil {
return nil, err
}
}
return m, nil
}
示例15: NewGPIO
// NewGPIO creates a new HD44780 connected by a 4-bit GPIO bus.
func NewGPIO(
rs, en, d4, d5, d6, d7, backlight interface{},
blPolarity BacklightPolarity,
rowAddr RowAddress,
modes ...ModeSetter,
) (*HD44780, error) {
pinKeys := []interface{}{rs, en, d4, d5, d6, d7, backlight}
pins := [7]embd.DigitalPin{}
for idx, key := range pinKeys {
if key == nil {
continue
}
var digitalPin embd.DigitalPin
if pin, ok := key.(embd.DigitalPin); ok {
digitalPin = pin
} else {
var err error
digitalPin, err = embd.NewDigitalPin(key)
if err != nil {
glog.V(1).Infof("hd44780: error creating digital pin %+v: %s", key, err)
return nil, err
}
}
pins[idx] = digitalPin
}
for _, pin := range pins {
if pin == nil {
continue
}
err := pin.SetDirection(embd.Out)
if err != nil {
glog.Errorf("hd44780: error setting pin %+v to out direction: %s", pin, err)
return nil, err
}
}
return New(
NewGPIOConnection(
pins[0],
pins[1],
pins[2],
pins[3],
pins[4],
pins[5],
pins[6],
blPolarity),
rowAddr,
modes...,
)
}