本文整理汇总了Golang中github.com/kidoman/embd.CloseGPIO函数的典型用法代码示例。如果您正苦于以下问题:Golang CloseGPIO函数的具体用法?Golang CloseGPIO怎么用?Golang CloseGPIO使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CloseGPIO函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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)
}
}
开发者ID:ninadk1092,项目名称:embd,代码行数:27,代码来源:gpio.go
示例2: main
func main() {
rowPins := []int{4, 17, 27, 22}
colPins := []int{23, 24, 25}
if err := embd.InitGPIO(); err != nil {
panic(err)
}
defer embd.CloseGPIO()
keypad, err := matrix4x3.New(rowPins, colPins)
if err != nil {
panic(err)
}
for {
key, err := keypad.PressedKey()
if err != nil {
panic(err)
}
if key != matrix4x3.KNone {
fmt.Printf("Key Pressed = %v\n", key)
}
time.Sleep(500 * time.Millisecond)
}
}
开发者ID:ninadk1092,项目名称:embd,代码行数:26,代码来源:matrix4x3.go
示例3: 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)
}
开发者ID:npotts,项目名称:embd,代码行数:29,代码来源:gpiointerrupt.go
示例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)
}
}
开发者ID:ninadk1092,项目名称:embd,代码行数:30,代码来源:watersensor.go
示例5: Close
func (g *GPIO) Close() error {
// close all the pins we have open if any
for _, pinState := range g.pinStates {
if pinState.Pin != nil {
switch pinObj := pinState.Pin.(type) {
case embd.DigitalPin:
pinObj.Close()
case embd.PWMPin:
pinObj.Close()
case BlasterPin:
pinObj.Close()
}
}
}
// if its a raspberry pi close pi-blaster too
host, _, err := embd.DetectHost()
if err != nil {
return err
}
if host == embd.HostRPi {
CloseBlaster()
}
err = embd.CloseGPIO()
if err != nil {
return err
}
return nil
}
开发者ID:hpssjellis,项目名称:serial-port-json-server,代码行数:30,代码来源:gpio_linux_arm.go
示例6: main
func main() {
embd.InitGPIO()
defer embd.CloseGPIO()
embd.SetDirection(10, embd.Out)
embd.DigitalWrite(10, embd.High)
}
开发者ID:bhawdeadlydan,项目名称:thebot,代码行数:7,代码来源:gpioshort.go
示例7: main
func main() {
if err := embd.InitGPIO(); err != nil {
panic(err)
}
defer embd.CloseGPIO()
pin, err := embd.NewAnalogPin(0)
if err != nil {
panic(err)
}
defer pin.Close()
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt, os.Kill)
defer signal.Stop(quit)
for {
select {
case <-time.After(100 * time.Millisecond):
val, err := pin.Read()
if err != nil {
panic(err)
}
fmt.Printf("reading: %v\n", val)
case <-quit:
return
}
}
}
开发者ID:bhawdeadlydan,项目名称:thebot,代码行数:29,代码来源:analog.go
示例8: main
func main() {
embd.InitGPIO()
defer embd.CloseGPIO()
val, _ := embd.AnalogRead(0)
fmt.Printf("Reading: %v\n", val)
}
开发者ID:bhawdeadlydan,项目名称:thebot,代码行数:7,代码来源:analogshort.go
示例9: 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)
}
}
开发者ID:bhawdeadlydan,项目名称:thebot,代码行数:28,代码来源:us020.go
示例10: Close
func (b *buttons) Close() {
log.Println("Closing buttons...")
for _, gpioBtn := range b.gpioBtns {
gpioBtn.pin.Close()
}
log.Println("Closing GPIO...")
embd.CloseGPIO()
}
开发者ID:fgrehm,项目名称:pucrs-iot-experiment,代码行数:9,代码来源:buttons.go
示例11: hardware
func hardware() {
if err := embd.InitGPIO(); err != nil {
panic(err)
}
defer embd.CloseGPIO()
if err := embd.InitSPI(); err != nil {
panic(err)
}
defer embd.CloseSPI()
lights, err := OpenLights()
if err != nil {
panic(err)
}
defer lights.Close()
digits, err := OpenDigits()
if err != nil {
panic(err)
}
defer digits.Close()
go digits.Try()
for !quit {
statusMutex.Lock()
yellow := status.Warning
red := status.Critical
redBlink := status.Paging
green := !(red || yellow)
//lastPageTime := status.LastPageTime
statusMutex.Unlock()
var redVal int
var yellowVal int
var greenVal int
if red {
redVal = embd.High
}
if yellow {
yellowVal = embd.High
}
if green {
greenVal = embd.High
}
lights.redPin.Write(redVal)
lights.yellowPin.Write(yellowVal)
lights.greenPin.Write(greenVal)
time.Sleep(500 * time.Millisecond)
if red && redBlink {
lights.redPin.Write(embd.Low)
}
time.Sleep(500 * time.Millisecond)
}
}
开发者ID:apparentlymart,项目名称:failinator,代码行数:56,代码来源:main.go
示例12: main
func main() {
if err := embd.InitGPIO(); err != nil {
panic(err)
}
defer embd.CloseGPIO()
pwm, err := embd.NewPWMPin("P9_14")
if err != nil {
panic(err)
}
defer pwm.Close()
if err := pwm.SetDuty(embd.BBBPWMDefaultPeriod / 2); err != nil {
panic(err)
}
time.Sleep(1 * time.Second)
}
开发者ID:bhawdeadlydan,项目名称:thebot,代码行数:18,代码来源:pwm.go
示例13: main
func main() {
fmt.Println("initGpio called")
var err error
if err = embd.InitGPIO(); err != nil {
panic(err)
}
defer embd.CloseGPIO()
s := newServo("P9_14")
for i := 0; i < 18; i++ {
angle := 10 + (10 * i)
fmt.Printf("Setting angle: %v\n", angle)
if err := s.SetAngle(angle); err != nil {
panic(err)
}
time.Sleep(1 * time.Second)
}
}
开发者ID:kunalpowar,项目名称:spikes,代码行数:18,代码来源:bbb_servo.go
示例14: main
func main() {
pinnr := flag.Int("pin", -1, "gpio pin number of LED")
flag.Parse()
if *pinnr < 0 {
fmt.Println("Please specify pin which LED is on! Be careful!")
os.Exit(1)
}
panicIf(embd.InitGPIO())
defer embd.CloseGPIO()
l := led.New(*pinnr)
if flag.NArg() <= 0 {
fmt.Println("Blinking Heartbeat1000 pattern till you quit...")
l.Blink(led.Heartbeat1000...)
} else {
pattern := make([]time.Duration, flag.NArg())
for i, s := range flag.Args() {
d, err := time.ParseDuration(s)
if err != nil {
fmt.Println("Error parsing duration:", err)
os.Exit(1)
}
pattern[i] = d
}
fmt.Printf("Blinking your pattern %v till you quit...\n", pattern)
l.Blink(pattern...)
}
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
fmt.Println("\nBye-bye.")
go func() {
// This we do in case l.Stop() doesn't work.
// It's a way to force quit.
<-c
os.Exit(1)
}()
l.Stop()
}
开发者ID:cassava,项目名称:pillr,代码行数:44,代码来源:main.go
示例15: main
func main() {
if err := embd.InitGPIO(); err != nil {
panic(err)
}
defer embd.CloseGPIO()
led, err := embd.NewDigitalPin(17)
if err != nil {
panic(err)
}
defer led.Close()
if err := led.SetDirection(embd.In); err != nil {
panic(err)
}
state := false
count := 0
for {
pin, err := led.Read()
if err != nil {
panic(err)
}
if pin == 1 {
if state == false {
count++
}
} else {
count = 0
state = false
}
if count >= 3 {
state = true
count = 0
client.SendCounterTick("GAS_1")
}
time.Sleep(10 * time.Millisecond)
}
}
开发者ID:b00lduck,项目名称:raspberry-energy-monitor,代码行数:44,代码来源:acquisition.go
示例16: main
func main() {
flag.Parse()
h, _, err := embd.DetectHost()
if err != nil {
return
}
var pinNo interface{}
switch h {
case embd.HostBBB:
pinNo = "P9_31"
case embd.HostRPi:
pinNo = 10
default:
panic("host not supported (yet :P)")
}
if err := embd.InitGPIO(); err != nil {
panic(err)
}
defer embd.CloseGPIO()
led, err := embd.NewDigitalPin(pinNo)
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)
}
}
开发者ID:ninadk1092,项目名称:embd,代码行数:43,代码来源:gpiodetect.go
示例17: 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
}
}
}
开发者ID:ralreegorganon,项目名称:embd,代码行数:43,代码来源:sht1x.go
示例18: main
func main() {
if err := embd.InitGPIO(); err != nil {
panic(err)
}
defer embd.CloseGPIO()
if err := embd.SetDirection(10, embd.Out); err != nil {
panic(err)
}
if err := embd.DigitalWrite(10, embd.High); err != nil {
panic(err)
}
time.Sleep(1 * time.Second)
if err := embd.SetDirection(10, embd.In); err != nil {
panic(err)
}
}
开发者ID:bhawdeadlydan,项目名称:thebot,代码行数:19,代码来源:gpiodirect.go
示例19: main
func main() {
flag.Parse()
embd.InitGPIO()
defer embd.CloseGPIO()
pwm, err := embd.NewPWMPin("P9_14")
if err != nil {
panic(err)
}
defer pwm.Close()
servo := servo.New(pwm)
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt, os.Kill)
turnTimer := time.Tick(500 * time.Millisecond)
left := true
servo.SetAngle(90)
defer func() {
servo.SetAngle(90)
}()
for {
select {
case <-turnTimer:
left = !left
switch left {
case true:
servo.SetAngle(70)
case false:
servo.SetAngle(110)
}
case <-quit:
return
}
}
}
开发者ID:ninadk1092,项目名称:embd,代码行数:40,代码来源:servobbb.go
示例20: 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
}
}
}
开发者ID:ninadk1092,项目名称:embd,代码行数:39,代码来源:us020.go
注:本文中的github.com/kidoman/embd.CloseGPIO函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论