• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang embd.NewDigitalPin函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/kidoman/embd.NewDigitalPin函数的典型用法代码示例。如果您正苦于以下问题:Golang NewDigitalPin函数的具体用法?Golang NewDigitalPin怎么用?Golang NewDigitalPin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewDigitalPin函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:apparentlymart,项目名称:failinator,代码行数:30,代码来源:main.go


示例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)
	}
}
开发者ID:bhawdeadlydan,项目名称:thebot,代码行数:28,代码来源:us020.go


示例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
}
开发者ID:apparentlymart,项目名称:failinator,代码行数:32,代码来源:main.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: 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


示例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)
}
开发者ID:npotts,项目名称:embd,代码行数:29,代码来源:gpiointerrupt.go


示例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
}
开发者ID:fgrehm,项目名称:pucrs-iot-experiment,代码行数:29,代码来源:buttons.go


示例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}
}
开发者ID:cassava,项目名称:pillr,代码行数:9,代码来源:led.go


示例9: inputPin

func inputPin(n int) embd.DigitalPin {
	pin, err := embd.NewDigitalPin(n)
	if err != nil {
		panic(err)
	}
	pin.SetDirection(embd.In)

	return pin
}
开发者ID:HackerLoop,项目名称:goNerfTurret,代码行数:9,代码来源:shoot.go


示例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
}
开发者ID:HackerLoop,项目名称:goNerfTurret,代码行数:10,代码来源:shoot.go


示例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
		}
	}
}
开发者ID:ralreegorganon,项目名称:embd,代码行数:43,代码来源:sht1x.go


示例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
}
开发者ID:julianfez,项目名称:hkuvr1611,代码行数:12,代码来源:gpio_linux.go


示例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
		}
	}
}
开发者ID:ninadk1092,项目名称:embd,代码行数:39,代码来源:us020.go


示例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
}
开发者ID:ninadk1092,项目名称:embd,代码行数:24,代码来源:matrix4x3.go


示例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...,
	)
}
开发者ID:npotts,项目名称:embd,代码行数:50,代码来源:hd44780.go


示例16: 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


示例17: 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


示例18: main

func main() {
	glog.Info("main: starting up")

	flag.Parse()

	var car Car = NullCar
	if !*fakeCar {
		if err := embd.InitI2C(); err != nil {
			panic(err)
		}
		defer embd.CloseI2C()

		bus := embd.NewI2CBus(byte(*i2cBusNo))

		var cam Camera = NullCamera
		if !*fakeCam {
			cam = NewCamera(*camWidth, *camHeight, *camTurnImage, *camFps)
		}
		defer cam.Close()
		cam.Run()

		var comp Compass = NullCompass
		if !*fakeCompass {
			comp = NewCompass(bus)
		}
		defer comp.Close()

		var rf RangeFinder = NullRangeFinder
		if !*fakeRangeFinder {
			thermometer := bmp180.New(bus)
			defer thermometer.Close()

			if err := embd.InitGPIO(); err != nil {
				panic(err)
			}
			defer embd.CloseGPIO()

			echoPin, err := embd.NewDigitalPin(*echoPinNumber)
			if err != nil {
				panic(err)
			}
			triggerPin, err := embd.NewDigitalPin(*triggerPinNumber)
			if err != nil {
				panic(err)
			}

			rf = NewRangeFinder(echoPin, triggerPin, thermometer)
		}
		defer rf.Close()

		var fw FrontWheel = NullFrontWheel
		if !*fakeFrontWheel {
			sb := servoblaster.New()
			defer sb.Close()

			pwm := sb.Channel(*sbChannel)

			servo := servo.New(pwm)
			fw = &frontWheel{servo}
		}
		defer fw.Turn(0)

		var engine Engine = NullEngine
		if !*fakeEngine {
			ctrl := pca9685.New(bus, 0x41)
			defer ctrl.Close()

			pwm := ctrl.AnalogChannel(15)

			engine = NewEngine(pwm)
		}
		defer engine.Stop()

		var gyro Gyroscope = NullGyroscope
		if !*fakeGyro {
			gyro = NewGyroscope(bus, l3gd20.R250DPS)
		}
		defer gyro.Close()

		car = NewCar(bus, cam, comp, rf, gyro, fw, engine)
	}
	defer car.Close()

	ws := NewWebServer(car)
	ws.Run()

	quit := make(chan os.Signal, 1)
	signal.Notify(quit, os.Interrupt, os.Kill)
	<-quit

	glog.Info("main: all done")
}
开发者ID:bhawdeadlydan,项目名称:thebot,代码行数:92,代码来源:main.go


示例19: main

func main() {

	if err := embd.InitGPIO(); err != nil {
		panic(err)
	}
	defer embd.CloseGPIO()

	btn17, err := embd.NewDigitalPin(17)
	if err != nil {
		panic(err)
	}
	btn18, err := embd.NewDigitalPin(18)
	if err != nil {
		panic(err)
	}

	defer btn17.Close()
	defer btn18.Close()

	if err := btn17.SetDirection(embd.In); err != nil {
		panic(err)
	}
	if err := btn18.SetDirection(embd.In); err != nil {
		panic(err)
	}
	btn17.ActiveLow(false)
	btn18.ActiveLow(false)

	motion := make(chan embd.DigitalPin)
	err = btn17.Watch(embd.EdgeBoth, func(btn embd.DigitalPin) {
		motion <- btn
	})
	if err != nil {
		panic(err)
	}
	err = btn18.Watch(embd.EdgeBoth, func(btn embd.DigitalPin) {
		motion <- btn
	})
	if err != nil {
		panic(err)
	}

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)

	fmt.Println("listening...")
	dur, _ := time.ParseDuration("-5m")
	onTime := time.Now().Add(dur)
	for {
		select {
		case <-c:
			fmt.Println("bye")
			return
		case btn := <-motion:
			direction := getDirection(btn.N())
			v, _ := btn.Read()
			if v == 0 {
				log.Printf("Motion stopped from %s.\n", direction)
				continue
			}
			log.Printf("Motion detected from %s.\n", direction)
			if time.Since(onTime).Seconds() > 300 {
				turnScreenOn()
				onTime = time.Now()
			}

		}
	}
}
开发者ID:jonaz,项目名称:magicmirror,代码行数:69,代码来源:main.go


示例20: initHardware

func initHardware() {
	err := embd.InitGPIO()
	if err != nil {
		fmt.Println("GPIO ERR:", err)
		os.Exit(1)
	}
	relays = make([]embd.DigitalPin, 8)
	if err != nil {
		fmt.Println("GPIO ERR:", err)
		os.Exit(1)
	}
	relays[0], err = embd.NewDigitalPin(4) //7)
	if err != nil {
		fmt.Println("GPIO ERR:", err)
		os.Exit(1)
	}
	relays[1], err = embd.NewDigitalPin(17) //0)
	if err != nil {
		fmt.Println("GPIO ERR:", err)
		os.Exit(1)
	}
	relays[2], err = embd.NewDigitalPin(18) //1)
	if err != nil {
		fmt.Println("GPIO ERR:", err)
		os.Exit(1)
	}
	relays[3], err = embd.NewDigitalPin(27) //2)
	if err != nil {
		fmt.Println("GPIO ERR:", err)
		os.Exit(1)
	}
	relays[4], err = embd.NewDigitalPin(22) //3)
	if err != nil {
		fmt.Println("GPIO ERR:", err)
		os.Exit(1)
	}
	relays[5], err = embd.NewDigitalPin(23) //4)
	if err != nil {
		fmt.Println("GPIO ERR:", err)
		os.Exit(1)
	}
	relays[6], err = embd.NewDigitalPin(24) //5)
	if err != nil {
		fmt.Println("GPIO ERR:", err)
		os.Exit(1)
	}
	relays[7], err = embd.NewDigitalPin(25) //6)
	if err != nil {
		fmt.Println("GPIO ERR:", err)
		os.Exit(1)
	}
	for _, r := range relays {
		err = r.SetDirection(embd.Out)
		if err != nil {
			fmt.Println("GPIO ERR:", err)
			os.Exit(1)
		}
		err = r.Write(embd.Low)
		if err != nil {
			fmt.Println("GPIO ERR:", err)
			os.Exit(1)
		}
	}
}
开发者ID:immesys,项目名称:powerup,代码行数:64,代码来源:main.go



注:本文中的github.com/kidoman/embd.NewDigitalPin函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang embd.NewI2CBus函数代码示例发布时间:2022-05-23
下一篇:
Golang embd.InitGPIO函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap