Created
March 24, 2017 03:02
-
-
Save thomasv314/154c2ce722a9c70f8011b31dc684964c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"gobot.io/x/gobot/drivers/gpio" | |
"gobot.io/x/gobot/platforms/firmata" | |
"log" | |
) | |
func main() { | |
pinNumber := "2" | |
log.Println("Starting waterflow detection on pin", pinNumber) | |
firmataAdaptor := firmata.NewAdaptor("/dev/tty.usbmodem1421") | |
err := firmataAdaptor.Connect() | |
if err != nil { | |
log.Println("Connection error:", err) | |
} | |
driver := gpio.NewDirectPinDriver(firmataAdaptor, pinNumber) | |
err = driver.Start() | |
if err != nil { | |
log.Println("Driver start error:", err) | |
} | |
value := 5 | |
pulses := 0 | |
mlz := 0.0 | |
for { | |
newValue, err := driver.DigitalRead() | |
if newValue != value { | |
value = newValue | |
pulses++ | |
mlz = mlz + 2.25 | |
log.Println("pulse", pulses, "mls", mlz) | |
} | |
if err != nil { | |
log.Println("Error reading value:", err) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment