Created
October 12, 2013 13:01
-
-
Save demirhanaydin/6949793 to your computer and use it in GitHub Desktop.
Led blink example with pi_piper on Raspberry Pi
This file contains hidden or 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
require 'rubygems' | |
require 'pi_piper' | |
# include PiPiper | |
# blink example | |
def pin | |
@pin ||= PiPiper::Pin.new(pin: 17, direction: :out) | |
end | |
def counter | |
@counter ||= 0 | |
end | |
# unfortunately blink does not work properly, so use toggle method | |
def blink | |
pin.on? ? pin.off : pin.on | |
end | |
def toggle | |
if counter % 2 == 0 | |
pin.on | |
else | |
pin.off | |
end | |
# update counter | |
@counter += 1 | |
end | |
while true | |
# blink | |
toggle | |
sleep 0.5 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment