當前位置: 首頁>>代碼示例>>Golang>>正文


Golang hwio.DigitalWrite函數代碼示例

本文整理匯總了Golang中github.com/mrmorphic/hwio.DigitalWrite函數的典型用法代碼示例。如果您正苦於以下問題:Golang DigitalWrite函數的具體用法?Golang DigitalWrite怎麽用?Golang DigitalWrite使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了DigitalWrite函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main

func main() {
	// get a pin by name. You could also just use the logical pin number, but this is
	// more readable. On BeagleBone, USR0 is an on-board LED.
	ledPin, err := hwio.GetPin("USR1")

	// Generally we wouldn't expect an error, but perhaps someone is running this a
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	// Set the mode of the pin to output. This will return an error if, for example,
	// we were trying to set an analog input to an output.
	err = hwio.PinMode(ledPin, hwio.OUTPUT)

	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	// Run the blink forever
	for {
		hwio.DigitalWrite(ledPin, hwio.HIGH)
		hwio.Delay(1000)
		hwio.DigitalWrite(ledPin, hwio.LOW)
		hwio.Delay(1000)
	}
}
開發者ID:FyIoT,項目名稱:hwio,代碼行數:28,代碼來源:blink.go

示例2: readButton

func readButton(name string, buttonPin hwio.Pin, ledPin hwio.Pin) {

	//value readed from button, initially set to 0, because the button will not pressed
	oldValue := 0

	t1 := time.Now()

	// loop
	for {
		// Read the button value
		value, e := hwio.DigitalRead(buttonPin)
		if e != nil {
			panic(e)
		}
		t1 = time.Now() // time at this point
		// Did value change?
		if value != oldValue {
			fmt.Printf("[%s] %v (%d)\n", name, t1.Sub(t0), value)
			oldValue = value

			// Write the value to the led.
			if value == 1 {
				hwio.DigitalWrite(ledPin, hwio.HIGH)
			} else {
				hwio.DigitalWrite(ledPin, hwio.LOW)
			}
		}
	}

}
開發者ID:jssvgs,項目名稱:oshiwasp,代碼行數:30,代碼來源:3buttonsLed.go

示例3: readTracker

func readTracker(name string, trackerPin hwio.Pin) {

	oldValue := 0            //value readed from tracker, initially set to 0, because the tracker was innactive
	timeAction := time.Now() // time of the action detected

	// loop
	for theAcq.getState() != stateSTOPPED {
		// Read the tracker value
		value, e := hwio.DigitalRead(trackerPin)
		if e != nil {
			panic(e)
		}
		//timeActionOld=timeAction //store the last time
		timeAction = time.Now() // time at this point
		// Did value change?
		if (value == 1) && (value != oldValue) {
			if theAcq.getState() != statePAUSED {
				dataString := fmt.Sprintf("[%s], %v, %d\n",
					name, timeAction.Sub(theAcq.getTime0()), value)
				log.Println(dataString)
				theAcq.outputFile.WriteString(dataString)
			}

			// Write the value to the led indicating somewhat is happened
			if value == 1 {
				hwio.DigitalWrite(theOshi.actionLed, hwio.HIGH)
			} else {
				hwio.DigitalWrite(theOshi.actionLed, hwio.LOW)
			}
		}
		oldValue = value
	}
}
開發者ID:jssvgs,項目名稱:oshiwasp,代碼行數:33,代碼來源:BToshiwasp_0.go

示例4: blinkingLed

func blinkingLed(ledPin hwio.Pin) int {
	// loop
	for {
		hwio.DigitalWrite(ledPin, hwio.HIGH)
		hwio.Delay(500)
		hwio.DigitalWrite(ledPin, hwio.LOW)
		hwio.Delay(500)
	}
}
開發者ID:jssvgs,項目名稱:oshiwasp,代碼行數:9,代碼來源:BToshiwasp_0.go

示例5: SetStrike

func (h *Hardware) SetStrike(state string) {
	switch state {
	case "unlocked":
		hwio.DigitalWrite(h.OutStrike, 1)
	case "locked":
		hwio.DigitalWrite(h.OutStrike, 0)
	default:
		panic(errors.New("unknown state"))
	}
	h.LastOutStrike = state
}
開發者ID:drewp,項目名稱:homeauto,代碼行數:11,代碼來源:laundry.go

示例6: SetLed

func (h *Hardware) SetLed(state string) {
	switch state {
	case "on":
		hwio.DigitalWrite(h.OutLed, 1)
	case "off":
		hwio.DigitalWrite(h.OutLed, 0)
	default:
		panic(errors.New("unknown state"))
	}
	h.LastOutLed = state
}
開發者ID:drewp,項目名稱:homeauto,代碼行數:11,代碼來源:laundry.go

示例7: resumeHandler

func resumeHandler(w http.ResponseWriter, r *http.Request) {

	theAcq.setStateRUNNING()

	p := &Page{Title: "Start", Body: "State: " + theAcq.state}
	hwio.DigitalWrite(theOshi.statusLed, hwio.HIGH)

	renderTemplate(w, "start", p)
}
開發者ID:jssvgs,項目名稱:oshiwasp,代碼行數:9,代碼來源:BToshiwasp_0.go

示例8: main

func main() {

	//value readed from button, initially set to 0, because the button will not pressed
	oldValue := 0

	// Set up 'button' as an input
	button, e := hwio.GetPinWithMode(buttonPin, hwio.INPUT)
	if e != nil {
		panic(e)
	}

	// Set up 'led' as an output
	led, e := hwio.GetPinWithMode(ledPin, hwio.OUTPUT)
	if e != nil {
		panic(e)
	}

	fmt.Printf("Beginning.....\n")
	t0 := time.Now() // time 0

	for {
		// Read the button value
		value, e := hwio.DigitalRead(button)
		t1 := time.Now() // time at this point
		if e != nil {
			panic(e)
		}

		// Did value change?
		if value != oldValue {
			fmt.Printf("[%v] %d\n", t1.Sub(t0), value)
			oldValue = value

			// Write the value to the led.
			if value == 1 {
				hwio.DigitalWrite(led, hwio.HIGH)
			} else {
				hwio.DigitalWrite(led, hwio.LOW)
			}
		}

	}
}
開發者ID:jssvgs,項目名稱:oshiwasp,代碼行數:43,代碼來源:buttonled.go

示例9: stopHandler

func stopHandler(w http.ResponseWriter, r *http.Request) {

	theAcq.setStateSTOPPED()
	hwio.DigitalWrite(theOshi.statusLed, hwio.LOW)
	log.Println("Finnishing.....")
	// close the GPIO pins
	//hwio.CloseAll()
	theAcq.closeOutputFile() //close the file when finished
	p := &Page{Title: "Stop", Body: "State: " + theAcq.state}
	renderTemplate(w, "stop", p)
	//log.Printf("There are %v goroutines", runtime.NumGoroutine())
}
開發者ID:jssvgs,項目名稱:oshiwasp,代碼行數:12,代碼來源:BToshiwasp_0.go

示例10: readTracker

func readTracker(name string, trackerPin hwio.Pin) {

	//value readed from tracker, initially set to 0, because the tracker was innactive
	oldValue := 0

	timeAction := time.Now()    // time of the action detected
	timeActionOld := time.Now() // time of the action-1 detected

	//fmt.Printf("[%s] File: %s\n",name,outputFile)

	// loop
	for {
		// Read the tracker value
		value, e := hwio.DigitalRead(trackerPin)
		if e != nil {
			panic(e)
		}
		timeActionOld = timeAction //store the last time
		timeAction = time.Now()    // time at this point
		// Did value change?
		if value != oldValue {
			dataString := fmt.Sprintf("[%s] %v (%v) -> %d\n",
				name, timeAction.Sub(t0), timeAction.Sub(timeActionOld), value)
			//fmt.Printf("[%s] %v (%v) -> %d\n",
			//           name,timeAction.Sub(t0),timeAction.Sub(timeActionOld),value)
			fmt.Printf(dataString)
			outputFile.WriteString(dataString)
			oldValue = value

			// Write the value to the led indicating somewhat is happened
			if value == 1 {
				hwio.DigitalWrite(actionLed, hwio.HIGH)
			} else {
				hwio.DigitalWrite(actionLed, hwio.LOW)
			}
		}
	}
}
開發者ID:jssvgs,項目名稱:oshiwasp,代碼行數:38,代碼來源:oshiwasp.go

示例11: main

func main() {
	// Get the pins we're going to use. These are on a beaglebone.
	sinPin, _ := hwio.GetPin("P9.11")
	sclkPin, _ := hwio.GetPin("P9.12")
	xlatPin, _ := hwio.GetPin("P9.13")
	gsclkPin, _ := hwio.GetPin("P9.14")
	blankPin, _ := hwio.GetPin("P9.15")

	fmt.Printf("Pins are: sin=%d, sclk=%d, xlat=%d, gsclk=%d, blank=%d", sinPin, sclkPin, xlatPin, gsclkPin, blankPin)
	// Make them all outputs
	e := hwio.PinMode(sinPin, hwio.OUTPUT)
	if e == nil {
		hwio.PinMode(sclkPin, hwio.OUTPUT)
	}
	if e == nil {
		hwio.PinMode(xlatPin, hwio.OUTPUT)
	}
	if e == nil {
		hwio.PinMode(gsclkPin, hwio.OUTPUT)
	}
	if e == nil {
		hwio.PinMode(blankPin, hwio.OUTPUT)
	}
	if e != nil {
		fmt.Printf("Could not initialise pins: %s", e)
		return
	}

	// set clocks low
	hwio.DigitalWrite(sclkPin, hwio.LOW)
	hwio.DigitalWrite(xlatPin, hwio.LOW)
	hwio.DigitalWrite(gsclkPin, hwio.LOW)

	// run GS clock in it's own space
	hwio.DigitalWrite(blankPin, hwio.HIGH)
	hwio.DigitalWrite(blankPin, hwio.LOW)
	clockData(gsclkPin)

	for b := 0; b < 4096; b++ {
		writeData(uint(b), sinPin, sclkPin, xlatPin)

		for j := 0; j < 10; j++ {
			hwio.DigitalWrite(blankPin, hwio.HIGH)
			hwio.DigitalWrite(blankPin, hwio.LOW)
			clockData(gsclkPin)
		}

		//		hwio.Delay(100)
	}

	//		hwio.ShiftOut(dataPin, clockPin, uint(data), hwio.MSBFIRST)
}
開發者ID:FyIoT,項目名稱:hwio,代碼行數:52,代碼來源:tlc5940.go

示例12: main

func main() {
	// Get the pins we're going to use. These are on a beaglebone.
	dataPin, _ := hwio.GetPin("P8.3")  // connected to pin 14
	clockPin, _ := hwio.GetPin("P8.4") // connected to pin 11
	storePin, _ := hwio.GetPin("P8.5") // connected to pin 12

	// Make them all outputs
	hwio.PinMode(dataPin, hwio.OUTPUT)
	hwio.PinMode(clockPin, hwio.OUTPUT)
	hwio.PinMode(storePin, hwio.OUTPUT)

	data := 0

	// Set the initial state of the clock and store pins to low. These both
	// trigger on the rising edge.
	hwio.DigitalWrite(clockPin, hwio.LOW)
	hwio.DigitalWrite(storePin, hwio.LOW)

	for {
		// Shift out 8 bits
		hwio.ShiftOut(dataPin, clockPin, uint(data), hwio.MSBFIRST)

		// You can use this line instead to clock out 16 bits if you have
		// two 74HC595's chained together
		// hwio.ShiftOutSize(dataPin, clockPin, uint(data), hwio.MSBFIRST, 16)

		// Pulse the store pin once
		hwio.DigitalWrite(storePin, hwio.HIGH)
		hwio.DigitalWrite(storePin, hwio.LOW)

		// Poor humans cannot read binary as fast as the machine can display it
		hwio.Delay(100)

		data++
	}
}
開發者ID:FyIoT,項目名稱:hwio,代碼行數:36,代碼來源:shiftout.go

示例13: startHandler

func startHandler(w http.ResponseWriter, r *http.Request) {

	// manage file depending the previous state
	if theAcq.getState() == stateSTOPPED {
		theAcq.reopenOutputFile()
		log.Printf("Reopen file %s\n", theAcq.outputFile)
	}

	// sets the new time0 only with a new scenery
	if theAcq.getState() == stateNEW {
		theAcq.setTime0()
	}

	theAcq.setStateRUNNING()

	//waitTillButtonPushed(buttonA)
	p := &Page{Title: "Start", Body: "State: " + theAcq.state}
	hwio.DigitalWrite(theOshi.statusLed, hwio.HIGH)
	log.Println("Beginning.....")

	renderTemplate(w, "start", p)

	// launch the trackers

	log.Printf("There are %v goroutines", runtime.NumGoroutine())
	log.Printf("Launching the Gourutines")

	go theAcq.readFromArduino2()
	log.Println("Started Arduino")
	go readTracker("A", theOshi.trackerA)
	log.Println("Started Tracker A")
	go readTracker("B", theOshi.trackerB)
	log.Println("Started Tracker B")
	go readTracker("C", theOshi.trackerC)
	log.Println("Started Tracker C")
	go readTracker("D", theOshi.trackerD)
	log.Println("Started Tracker D")

	log.Printf("There are %v goroutines", runtime.NumGoroutine())
}
開發者ID:jssvgs,項目名稱:oshiwasp,代碼行數:40,代碼來源:BToshiwasp_0.go

示例14: writeData

// val is a 12-bit int
func writeData(val uint, sinPin hwio.Pin, sclkPin hwio.Pin, xlatPin hwio.Pin) {
	fmt.Printf("writing data %d\n", val)
	bits := 0
	mask := uint(1) << 11
	for i := 0; i < 16; i++ {
		v := val
		for j := 0; j < 12; j++ {
			if (v & mask) != 0 {
				hwio.DigitalWrite(sinPin, hwio.HIGH)
			} else {
				hwio.DigitalWrite(sinPin, hwio.HIGH)
			}
			hwio.DigitalWrite(sclkPin, hwio.HIGH)
			hwio.DigitalWrite(sclkPin, hwio.LOW)

			v = v << 1
			bits++
		}
	}

	hwio.DigitalWrite(xlatPin, hwio.HIGH)
	hwio.DigitalWrite(xlatPin, hwio.LOW)
	fmt.Printf("Wrote %d bits\n", bits)
}
開發者ID:FyIoT,項目名稱:hwio,代碼行數:25,代碼來源:tlc5940.go

示例15: clockData

func clockData(gsclkPin hwio.Pin) {
	for g := 0; g < 4096; g++ {
		hwio.DigitalWrite(gsclkPin, hwio.HIGH)
		hwio.DigitalWrite(gsclkPin, hwio.LOW)
	}
}
開發者ID:FyIoT,項目名稱:hwio,代碼行數:6,代碼來源:tlc5940.go


注:本文中的github.com/mrmorphic/hwio.DigitalWrite函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。