当前位置: 首页>>代码示例>>Golang>>正文


Golang embd.NewDigitalPin函数代码示例

本文整理汇总了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
}
开发者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


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