Skip to content

Commit 958c689

Browse files
zankichkkallday
authored andcommitted
Add grovepi GetValue
Signed-off-by: Kevin Kelani <[email protected]>
1 parent 0e30128 commit 958c689

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

grovepi/grovepi.go

+14
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ func (g *GrovePI) Open() (gpiodriver.Conn, error) {
6767
// Value returns the value of the pin. 0 for low values, 1 for high.
6868
func (g *GrovePI) Value(pin string) (int, error) { return 0, nil }
6969

70+
// GetValue gets the value of the pin. 0 for low values, 1 for high.
71+
func (g *GrovePI) GetValue(pin string) (int, error) {
72+
if err := g.Conn.Write([]byte{1, digitalRead, byte(pinMap[pin]), 0, 0}); err != nil {
73+
return 0, err
74+
}
75+
time.Sleep(100 * time.Millisecond)
76+
buf := make([]byte, 1)
77+
if err := g.Conn.ReadReg(1, buf); err != nil {
78+
return 0, err
79+
}
80+
81+
return int(buf[0]), nil
82+
}
83+
7084
// SetValue sets the value of the pin. 0 for low values, 1 for high.
7185
func (g *GrovePI) SetValue(pin string, v int) error {
7286
if !strings.HasPrefix(pin, "D") {

0 commit comments

Comments
 (0)