Exemplo n.º 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)
	}
}
Exemplo n.º 2
0
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)
}
Exemplo n.º 3
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++
	}
}
Exemplo n.º 4
0
// 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)
}
Exemplo n.º 5
0
func clockData(gsclkPin hwio.Pin) {
	for g := 0; g < 4096; g++ {
		hwio.DigitalWrite(gsclkPin, hwio.HIGH)
		hwio.DigitalWrite(gsclkPin, hwio.LOW)
	}
}