Exemple #1
0
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)
	}
}
Exemple #2
0
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++
	}
}