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)) } }
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() }
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) } }