예제 #1
0
func spin(stepsPerMinute int, invert bool) {
	var pauseTime float64
	pauseTime = float64(60) / float64(stepsPerMinute)
	pfd := piface.NewPiFaceDigital(spi.DEFAULT_HARDWARE_ADDR, spi.DEFAULT_BUS, spi.DEFAULT_CHIP)

	// initializes pifacedigital board
	err := pfd.InitBoard()
	if err != nil {
		fmt.Printf("Error on init board: %s", err)
		return
	}
	if invert {
		pfd.Relays[0].SetValue(0)
		pfd.Relays[1].SetValue(1)
	} else {
		pfd.Relays[0].SetValue(1)
		pfd.Relays[1].SetValue(0)
	}
	pfd.OutputPins[2].SetValue(0)
	running = true
	for running {
		pfd.OutputPins[2].Toggle()
		time.Sleep(time.Second / 10)
		pfd.OutputPins[2].Toggle()
		if pfd.InputPins[0].Value() == 1 {
			pfd.Relays[0].Toggle()
			pfd.Relays[1].Toggle()
		}
		time.Sleep(time.Duration(float64(time.Second) * pauseTime))
	}
}
예제 #2
0
func testMotor() {
	// creates a new pifacedigital instance
	pfd := piface.NewPiFaceDigital(spi.DEFAULT_HARDWARE_ADDR, spi.DEFAULT_BUS, spi.DEFAULT_CHIP)

	// initializes pifacedigital board
	err := pfd.InitBoard()
	if err != nil {
		fmt.Printf("Error on init board: %s", err)
		return
	}
	pfd.OutputPins[0].Toggle()
	time.Sleep(time.Second / 10)
	pfd.OutputPins[0].Toggle()
}
예제 #3
0
파일: blink_piface.go 프로젝트: xqbumu/goPi
func main() {

	// creates a new pifacedigital instance
	pfd := piface.NewPiFaceDigital(spi.DEFAULT_HARDWARE_ADDR, spi.DEFAULT_BUS, spi.DEFAULT_CHIP)

	// initializes pifacedigital board
	err := pfd.InitBoard()
	if err != nil {
		fmt.Printf("Error on init board: %s", err)
		return
	}

	// blink time!!
	fmt.Println("Blinking led 7 each second")
	for {
		pfd.Leds[7].Toggle()
		time.Sleep(time.Second)
	}
}