Last active
August 29, 2015 14:11
-
-
Save tchap/13d7f59f04eecdd3ce4f to your computer and use it in GitHub Desktop.
Read toilet sensors on Raspberry Pi
This file contains 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
// Demo: | |
// | |
// $ sudo ./pins | |
// Unable to select a suitable driver for this board. | |
// Linux itoilet 3.12.28+ #709 PREEMPT Mon Sep 8 15:28:00 BST 2014 armv6l GNU/Linux | |
// | |
// toilet A: 0 | |
// toilet B: 0 | |
// | |
// BTW hwio has a terrible public API, brb. | |
package main | |
import ( | |
"fmt" | |
"log" | |
"os" | |
"github.com/mrmorphic/hwio" | |
) | |
func main() { | |
if err := run(); err != nil { | |
log.Fatalln("Error:", err) | |
} | |
} | |
func run() error { | |
hwio.SetDriver(new(hwio.RaspberryPiDTDriver)) | |
defer hwio.CloseAll() | |
// Pin 22 = "gpio25" | |
toiletA, err := hwio.GetPinWithMode("gpio25", hwio.INPUT) | |
if err != nil { | |
return err | |
} | |
// Pin 24 = "gpio8" | |
toiletB, err := hwio.GetPinWithMode("gpio8", hwio.INPUT) | |
if err != nil { | |
return err | |
} | |
valueA, err := hwio.DigitalRead(toiletA) | |
if err != nil { | |
return err | |
} | |
valueB, err := hwio.DigitalRead(toiletB) | |
if err != nil { | |
return err | |
} | |
fmt.Printf("toilet A: %v\n", valueA) | |
fmt.Printf("toilet B: %v\n", valueB) | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment