Advertisement
Guest User

chrisyoubastard

a guest
Jun 23rd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "net/http"
  6. "time"
  7.  
  8. "github.com/stianeikeland/go-rpio"
  9. )
  10.  
  11.  
  12. func indexHandler(w http.ResponseWriter, r *http.Request) {
  13. fmt.Fprintf(w, "<html><a href='/open'><div style="width:200px;height:100px;background:green;padding:auto;">Open Door</div></a></html>")
  14. }
  15.  
  16. func openHandler(w http.ResponseWriter, r *http.Request) {
  17. // do stuff here
  18. err := rpio.Open()
  19.  
  20. pin := rpio.Pin(10)
  21. pin.High()
  22. time.Sleep(1 * time.Second)
  23. pin.Low)
  24. fmt.Fprintf(w, "<html><a href='/open'><div style="width:200px;height:100px;background:green;padding:auto;">Open Door</div></a></html>")
  25. }
  26.  
  27. func main() {
  28. http.HandleFunc("/", indexHandler)
  29. http.HandleFunc("/open", openHandler)
  30. http.ListenAndServe(":8080", nil)
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement