Last active
January 2, 2016 20:19
-
-
Save lucansky/8356312 to your computer and use it in GitHub Desktop.
Clock 595 shift registers
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
require "wiringpi" | |
#GC.disable | |
io = WiringPi::GPIO.new | |
digits = [ | |
[1,1,0,0,0,0,0,0], #0 | |
[1,1,1,1,1,0,0,1], #1 | |
[1,0,1,0,0,1,0,0], #2 | |
[1,0,1,1,0,0,0,0], #3 | |
[1,0,0,1,1,0,0,1], #4 | |
[1,0,0,1,0,0,1,0], #5 | |
[1,0,0,0,0,0,1,0], #6 | |
[1,1,0,1,1,0,0,0], #7 | |
[1,0,0,0,0,0,0,0], #8 | |
[1,0,0,1,0,0,0,0] #9 | |
] | |
pos = [ | |
[0,0,0,0,0,0,0,1], | |
[0,0,0,0,0,0,1,0], | |
[0,0,0,0,0,1,0,0], | |
[0,0,0,0,1,0,0,0], | |
[0,0,0,1,0,0,0,0], | |
[0,0,1,0,0,0,0,0], | |
[0,1,0,0,0,0,0,0], | |
[1,0,0,0,0,0,0,0] | |
] | |
loop do | |
# Example: "23254030" | |
time = Time.now.strftime("%H%M%S%2N") | |
# Array of digits to display, in reverse | |
time_array = time.split(//).map(&:to_i).reverse | |
0.upto(7) do |position| | |
digit_array = digits[time_array[position]].dup | |
# Enable dot every 2 digits | |
digit_array[0] = 0 if (position % 2 == 0) | |
io.shiftOutArray(0,1,2, digit_array+pos[position]) | |
sleep 0.001 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment