Skip to content

Commit

Permalink
ScrollPhat basic binary clock example
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Mar 12, 2016
1 parent 46b451f commit 58b3339
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions examples/scrollphat-binary-clock.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env ruby
require 'wiringpi'
STDOUT.write """ScrollPhat Binary Clock
ScrollPhat will show hour, minute and second in binary across 3 lines.
Press Ctrl+C to exit.
"""
class Clock < WiringPi::ScrollPhat

@@running = false

def tick
time = Time.new
x = 0
y = 0
[time.hour, time.min, time.sec].each do |p|
p.to_s(2).rjust(8,'0').split('').each do |d|
self.point(x, y, d.to_i)
x+=1
end
y+=2
x=0
end
self.update
end

def go!
@@running = true
trap("SIGINT") { self.stop! }
while @@running
self.tick
sleep 0.1
end
end

def stop!
STDOUT.write "\nGoodbye!\n"
@@running = false
end

end

clock = Clock.new
clock.go!

0 comments on commit 58b3339

Please sign in to comment.