Documentation ¶
Overview ¶
Example ¶
package main import ( "log" "time" "github.com/benmcclelland/gogrove" ) func main() { s, err := gogrove.New() if err != nil { log.Fatal(err) } defer s.Close() // blink LED on D6, errors ignored for i := 0; i < 5; i++ { s.TurnOn(gogrove.PortD6) time.Sleep(time.Second) s.TurnOff(gogrove.PortD6) time.Sleep(time.Second) } }
Output:
Example (GreenTxtLCD) ¶
package main import ( "log" "github.com/benmcclelland/gogrove" ) func main() { l, err := gogrove.NewLCD() if err != nil { log.Fatal(err) } defer l.Close() l.ClearText() l.SetText("Hello,\nGo Example") l.SetRGB(0, 255, 0) }
Output:
Example (OffClearLCD) ¶
package main import ( "log" "github.com/benmcclelland/gogrove" ) func main() { l, err := gogrove.NewLCD() if err != nil { log.Fatal(err) } defer l.Close() l.ClearText() l.SetRGB(0, 0, 0) }
Output:
Index ¶
- Constants
- type LCD
- type Session
- func (s *Session) AnalogRead(port uint8) (uint16, error)
- func (s *Session) AnalogWrite(port, value uint8) error
- func (s *Session) Close() error
- func (s *Session) DigitalRead(port uint8) (uint8, error)
- func (s *Session) DigitalWrite(port, value uint8) error
- func (s *Session) GetFirmwareVersion() (string, error)
- func (s *Session) IsOn(port uint8) bool
- func (s *Session) ReadDHT(port, sensor uint8) (float32, float32, error)
- func (s *Session) ReadUltraSonic(port uint8) (uint16, error)
- func (s *Session) SetPortMode(port, mode uint8) error
- func (s *Session) TurnOff(port uint8) error
- func (s *Session) TurnOn(port uint8) error
Examples ¶
Constants ¶
const ( // PortA0 is the value for GrovePi A0 PortA0 uint8 = 0 // PortA1 is the value for GrovePi A1 PortA1 uint8 = 1 // PortA2 is the value for GrovePi A2 PortA2 uint8 = 2 // PortD2 is the value for GrovePi D2 PortD2 uint8 = 2 // PortD3 is the value for GrovePi D3 PortD3 uint8 = 3 // PortD4 is the value for GrovePi D4 PortD4 uint8 = 4 // PortD5 is the value for GrovePi D5 PortD5 uint8 = 5 // PortD6 is the value for GrovePi D6 PortD6 uint8 = 6 // PortD7 is the value for GrovePi D7 PortD7 uint8 = 7 // PortD8 is the value for GrovePi D8 PortD8 uint8 = 8 // ModeInput is used for SetPortMode to input ModeInput uint8 = 0 // ModeOutput is used for SetPortMode to output ModeOutput uint8 = 1 // BlueDHTSensor is the DHT sensor that comes with base kit BlueDHTSensor uint8 = 0 // WhiteDHTSensor is the separate white DHT sensor WhiteDHTSensor uint8 = 1 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LCD ¶
LCD holds session info for interacting with GrovePi LCD
type Session ¶
Session holds session info for interacting with GrovePi
func NewWithAddress ¶
NewWithAddress initializes new session with given GrovePi address
func (*Session) AnalogRead ¶
AnalogRead reads analog value from port this is only valid for PortA0, PortA1, or PortA2 the returned value will be between 0-1023 inclusive
func (*Session) AnalogWrite ¶
AnalogWrite writes value 0-255 inclusive to given port This appears to only be valid for PortD3, PortD5, and PortD6 using PWM write
func (*Session) DigitalRead ¶
DigitalRead return the value from a digital port on success, this will be either 0 or 1
func (*Session) DigitalWrite ¶
DigitalWrite sets the value for the given port The value must be 0 or 1
func (*Session) GetFirmwareVersion ¶
GetFirmwareVersion returns the GrovePi firmware version
Example ¶
package main import ( "fmt" "log" "github.com/benmcclelland/gogrove" ) func main() { s, err := gogrove.New() if err != nil { log.Fatal(err) } defer s.Close() vers, err := s.GetFirmwareVersion() if err != nil { log.Fatal(err) } fmt.Println(vers) }
Output:
func (*Session) IsOn ¶
IsOn is shorthand for DigitalRead on a digital port returning true if the port is 1 and false if the port is 0 this ignores errors from DigitalRead for easier inlining
func (*Session) ReadDHT ¶
ReadDHT returns temp (C), humidity (%), error must pass the sensort type, one of: gogrove.BlueDHTSensor gogrove.WhiteDHTSensor
func (*Session) ReadUltraSonic ¶
ReadUltraSonic returns distance in cm Sensor spec: measuring range 2-350cm, resolution 1cm
func (*Session) SetPortMode ¶
SetPortMode sets port to mode, for example: SetPortMode(gogrove.PortA0, gogrove.ModeOutput) SetPortMode(gogrove.PortD3, gogrove.ModeInput)
Example ¶
package main import ( "log" "github.com/benmcclelland/gogrove" ) func main() { s, err := gogrove.New() if err != nil { log.Fatal(err) } defer s.Close() // Set port D3 to Input err = s.SetPortMode(gogrove.PortD3, gogrove.ModeInput) if err != nil { log.Fatal(err) } }
Output: