forked from tumugin/WiringPi-Ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ScrollPhat basic binary clock example
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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! |