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


Golang embd.InitGPIO函数代码示例

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


在下文中一共展示了InitGPIO函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

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

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

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

示例5: main

func main() {
	embd.InitGPIO()
	defer embd.CloseGPIO()

	embd.SetDirection(10, embd.Out)
	embd.DigitalWrite(10, embd.High)
}
开发者ID:bhawdeadlydan,项目名称:thebot,代码行数:7,代码来源:gpioshort.go

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

示例7: Init

func (g *GPIO) Init(pinStateChanged chan PinState, pinAdded chan PinState, pinRemoved chan string, states map[string]PinState) error {
	g.pinStateChanged = pinStateChanged
	g.pinRemoved = pinRemoved
	g.pinAdded = pinAdded
	g.pinStates = states

	// if its a raspberry pi initialize pi-blaster too
	host, _, err := embd.DetectHost()
	if err != nil {
		return err
	}
	if host == embd.HostRPi {
		InitBlaster()
	}

	err = embd.InitGPIO()
	if err != nil {
		return err
	}
	// now init pins
	for key, pinState := range g.pinStates {
		if pinState.Name == "" {
			pinState.Name = pinState.PinId
		}
		g.PinInit(key, pinState.Dir, pinState.Pullup, pinState.Name)
		g.PinSet(key, pinState.State)
	}
	return nil
}
开发者ID:hpssjellis,项目名称:serial-port-json-server,代码行数:29,代码来源:gpio_linux_arm.go

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

示例9: main

func main() {
	embd.InitGPIO()
	defer embd.CloseGPIO()

	val, _ := embd.AnalogRead(0)
	fmt.Printf("Reading: %v\n", val)
}
开发者ID:bhawdeadlydan,项目名称:thebot,代码行数:7,代码来源:analogshort.go

示例10: init

func (p *PCD8544) init() {
	if err := embd.InitGPIO(); err != nil {
		panic(err)
	}
	// All pin direction are output
	embd.SetDirection(p.PIN_SCLK, embd.Out)
	embd.SetDirection(p.PIN_DIN, embd.Out)
	embd.SetDirection(p.PIN_DC, embd.Out)
	embd.SetDirection(p.PIN_CS, embd.Out)
	embd.SetDirection(p.PIN_RST, embd.Out)

	// Reset controller state
	embd.DigitalWrite(p.PIN_RST, embd.High)
	embd.DigitalWrite(p.PIN_CS, embd.High)
	embd.DigitalWrite(p.PIN_RST, embd.Low)
	// delay(100)
	time.Sleep(100 * time.Millisecond)
	embd.DigitalWrite(p.PIN_RST, embd.High)

	// LCD parameters
	p.send(LCD_CMD, 0x21) // extended instruction set control (H=1)
	p.send(LCD_CMD, 0x13) // bias system (1:48)
	p.send(LCD_CMD, 0xc2) // default Vop (3.06 + 66 * 0.06 = 7v)

	p.Clear()

	// Activate LCD
	p.send(LCD_CMD, 0x08) // display blank
	p.send(LCD_CMD, 0x0c) // normal mode (0x0d = inverse mode)
	// delay(100)
	time.Sleep(100 * time.Millisecond)

	// Place the cursor at the origin
	p.SetCursor(0, 0)
}
开发者ID:JokerQyou,项目名称:nlcd,代码行数:35,代码来源:pcd8544.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: init

func init() {
	log.Info("Init Shooter")
	embd.InitGPIO()

	pinTrigger1 = outputPin(trigger1, embd.High)
	pinTrigger2 = outputPin(trigger2, embd.High)
	pinTriggerReturn = inputPin(trigger2)
	pinSlowSwitch = outputPin(slowSwitch, embd.High)
	pinFastSwitch = outputPin(fastSwitch, embd.Low)

	startShooter()
}
开发者ID:HackerLoop,项目名称:goNerfTurret,代码行数:12,代码来源:shoot.go

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

示例14: Monitor_temperature_humidity

func (t *TemperatureController) Monitor_temperature_humidity(rw http.ResponseWriter, req *http.Request) {

	flag.Parse()
	embd.InitGPIO()
	// var lig models.Light

	sensorType := dht.DHT11
	temperature, humidity, retried, err := dht.ReadDHTxxWithRetry(sensorType, 4, true, 10)
	if err != nil {
		log.Fatal(err)
	}
	// Print temperature and humidity
	fmt.Printf("Temperature = %v*C, Humidity = %v%% (retried %d times)\n",
		temperature, humidity, retried)
	b, err := json.Marshal(models.WeatherMessage{
		Success:     "True",
		Message:     "Temperature and Humidity updated",
		Temperature: temperature,
		Humidity:    humidity,
	})
	if err != nil {
		log.Fatal(err)
	}
	rw.Header().Set("Content-Type", "application/json")
	rw.Write(b)
	// if temperature <= 22 {
	// 	embd.SetDirection(lig.Pin_number, embd.Out)
	// 	embd.DigitalWrite(lig.Pin_number, embd.High)
	// 	b, err := json.Marshal(models.WeatherLEDMessage{
	// 		Success: "True",
	// 		Message: "It's getting cooler!!",
	// 	})
	// 	if err != nil {
	// 		log.Fatal(err)
	// 	}
	// 	rw.Header().Set("Content-Type", "application/json")
	// 	rw.Write(b)
	// } else if temperature > 22 {
	// 	embd.SetDirection(lig.Pin_number, embd.Out)
	// 	embd.DigitalWrite(lig.Pin_number, embd.High)
	// 	b, err := json.Marshal(models.WeatherLEDMessage{
	// 		Success: "True",
	// 		Message: "It's getting hotter!!",
	// 	})
	// 	if err != nil {
	// 		log.Fatal(err)
	// 	}
	// 	rw.Header().Set("Content-Type", "application/json")
	// 	rw.Write(b)
	// }
}
开发者ID:Kedarnag13,项目名称:Home_Automation,代码行数:51,代码来源:weather_controller.go

示例15: NewRPi

func NewRPi() *RPi {
	pi := &RPi{LEDs: []string{"GPIO_17", "GPIO_27", "GPIO_22"}}
	err := embd.InitGPIO()
	if err != nil {
		fmt.Println(err.Error())
	}
	for _, l := range pi.LEDs {
		err := embd.SetDirection(l, embd.Out)
		if err != nil {
			fmt.Println(err.Error())
		}
	}
	return pi
}
开发者ID:alsm,项目名称:goIoT,代码行数:14,代码来源:ledborg.go


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