jwhitehorn / pi_piper

Event driven Raspberry Pi GPIO programming in Ruby
BSD 2-Clause "Simplified" License
694 stars 71 forks source link

.value always returns 0 in console #24

Closed foffer closed 8 years ago

foffer commented 10 years ago

In Ruby 2.1.2 on the Raspberry Pi B model using the Pry console (tested in IRB as well) Doing this: pin = PiPiper::Pin.new(:pin => 18, :direction => :out) correctly initialises the pin. pin.on / .off works correctly. But when calling pin.value it always returns 0. I've tried it using the update_value method instead of the on / off method, but the .value return is the same.

[3] pry(main)> pin = PiPiper::Pin.new(:pin => 18, :direction => :out) => #<PiPiper::Pin:0x1cdd648 @direction=:out, @invert=false, @last_value=nil, @pin=18, @pull=:off, @trigger=:both, @value=0> [4] pry(main)> pin.value => 0 [5] pry(main)> pin.update_value(1) => 1 [6] pry(main)> pin.value => 0 [7] pry(main)>

bguest commented 10 years ago

Just for clarification, what branch are you using?

foffer commented 10 years ago

I'm using v.2.0.beta4. Not actually sure what branch I'm on. How would i see that?

bguest commented 10 years ago

The develop branch is a bit a head of master, so just wanted to know where to look, looks like the issue is the same in both places. PiPiper::Pin just caches value, so unless you specifically tell it to read from the gpio it will just used the cached value. So in your case I believe if you add a pin.read after the update_value it should work.

foffer commented 10 years ago

Ahh, awesome, that worked! Thanks