func (oshi *Oshiwasp) initiate() { var e error // Set up 'trakers' as inputs oshi.trackerA, e = hwio.GetPinWithMode(trackerAPin, hwio.INPUT) if e != nil { panic(e) } log.Printf("Set pin %s as trackerA\n", trackerAPin) oshi.trackerB, e = hwio.GetPinWithMode(trackerBPin, hwio.INPUT) if e != nil { panic(e) } log.Printf("Set pin %s as trackerB\n", trackerBPin) oshi.trackerC, e = hwio.GetPinWithMode(trackerCPin, hwio.INPUT) if e != nil { panic(e) } log.Printf("Set pin %s as trackerC\n", trackerCPin) oshi.trackerD, e = hwio.GetPinWithMode(trackerDPin, hwio.INPUT) if e != nil { panic(e) } log.Printf("Set pin %s as trackerD\n", trackerDPin) // Set up 'buttons' as inputs oshi.buttonA, e = hwio.GetPinWithMode(buttonAPin, hwio.INPUT) if e != nil { panic(e) } log.Printf("Set pin %s as buttonA\n", buttonAPin) oshi.buttonB, e = hwio.GetPinWithMode(buttonBPin, hwio.INPUT) if e != nil { panic(e) } log.Printf("Set pin %s as buttonB\n", buttonBPin) // Set up 'leds' as outputs oshi.statusLed, e = hwio.GetPinWithMode(statusLedPin, hwio.OUTPUT) if e != nil { panic(e) } log.Printf("Set pin %s as statusLed\n", statusLedPin) oshi.actionLed, e = hwio.GetPinWithMode(actionLedPin, hwio.OUTPUT) if e != nil { panic(e) } log.Printf("Set pin %s as actionLed\n", actionLedPin) }
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) } } } }
func main() { // setup // Set up 'button' as an input button1, e := hwio.GetPinWithMode(buttonPin1, hwio.INPUT) if e != nil { panic(e) } button2, e := hwio.GetPinWithMode(buttonPin2, hwio.INPUT) if e != nil { panic(e) } button3, e := hwio.GetPinWithMode(buttonPin3, 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) } //e:= hwio.Led("OK", true) fmt.Printf("Beginning.....\n") t0 = time.Now() go readButton("Uno", button1, led) go readButton("Dos", button2, led) go readButton("Tres", button3, led) // wait fmt.Print("Enter to finish: ") var input string fmt.Scanln(&input) defer hwio.CloseAll() }
func main() { // setup // open file (create if not exists!) if len(os.Args) != 2 { fmt.Printf("Usage: %s fileBaseName\n", os.Args[0]) os.Exit(1) } t := time.Now() thisOutputFileName := fmt.Sprintf("%s_%d%02d%02d%02d%02d%02d.csv", os.Args[1], t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second()) thisOutputFile, e := os.Create(thisOutputFileName) if e != nil { panic(e) } fmt.Printf("File: %s\n", thisOutputFileName) outputFile = thisOutputFile // Set up 'trakers' as inputs trackerA, e := hwio.GetPinWithMode(trackerAPin, hwio.INPUT) if e != nil { panic(e) } trackerB, e := hwio.GetPinWithMode(trackerBPin, hwio.INPUT) if e != nil { panic(e) } trackerC, e := hwio.GetPinWithMode(trackerCPin, hwio.INPUT) if e != nil { panic(e) } trackerD, e := hwio.GetPinWithMode(trackerDPin, hwio.INPUT) if e != nil { panic(e) } // Set up 'buttons' as inputs buttonA, e := hwio.GetPinWithMode(buttonAPin, hwio.INPUT) if e != nil { panic(e) } buttonB, e := hwio.GetPinWithMode(buttonBPin, hwio.INPUT) if e != nil { panic(e) } // Set up 'leds' as outputs statusLed, e := hwio.GetPinWithMode(statusLedPin, hwio.OUTPUT) if e != nil { panic(e) } thisActionLed, e := hwio.GetPinWithMode(actionLedPin, hwio.OUTPUT) if e != nil { panic(e) } actionLed = thisActionLed fmt.Printf("Push button A to start, B to finish...\n") // read the button A change to init the data readdings waitTillButtonPushed(buttonA) hwio.DigitalWrite(statusLed, hwio.HIGH) t0 = time.Now() fmt.Printf("Beginning.....\n") // launch the trackers go readTracker("A", trackerA) go readTracker("B", trackerB) go readTracker("C", trackerC) go readTracker("D", trackerD) // wait till button B is pushed waitTillButtonPushed(buttonB) hwio.DigitalWrite(statusLed, hwio.LOW) fmt.Printf("Finnishing.....\n") //fmt.Print("Enter to finish: ") //var input string //fmt.Scanln(&input) // close the GPIO pins defer hwio.CloseAll() defer thisOutputFile.Close() //close the file when main finished }