Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'wiringpi'
DATA_PIN = 3
CLOCK_PIN = 2
LATCH_PIN = 0
NUM_OFF = 1
NUM_ON = 0
SEG_OFF = 0
SEG_ON = 1
#LSBFIRST = 0
#MSBFIRST = 1
message = `uptime` + ' ---- ' # 'this is not the prettiest font in the world - '
charOffset = 0
startTime = Time.now
WIO = WiringPi::GPIO.new(0)
WIO.mode DATA_PIN, OUTPUT
WIO.mode CLOCK_PIN, OUTPUT
WIO.mode LATCH_PIN, OUTPUT
@charMap = Hash[
'a' => [SEG_ON,SEG_ON,SEG_ON,SEG_OFF,SEG_ON,SEG_ON,SEG_ON],
'b' => [SEG_OFF,SEG_OFF,SEG_ON,SEG_ON,SEG_ON,SEG_ON,SEG_ON],
'c' => [SEG_ON,SEG_OFF,SEG_OFF,SEG_ON,SEG_ON,SEG_ON,SEG_OFF],
'd' => [SEG_OFF,SEG_ON,SEG_ON,SEG_ON,SEG_ON,SEG_OFF,SEG_ON],
'e' => [SEG_ON,SEG_OFF,SEG_OFF,SEG_ON,SEG_ON,SEG_ON,SEG_ON],
'f' => [SEG_ON,SEG_OFF,SEG_OFF,SEG_OFF,SEG_ON,SEG_ON,SEG_ON],
'g' => [SEG_ON,SEG_OFF,SEG_ON,SEG_ON,SEG_ON,SEG_ON,SEG_OFF],
'h' => [SEG_OFF,SEG_OFF,SEG_ON,SEG_OFF,SEG_ON,SEG_ON,SEG_ON],
'i' => [SEG_OFF,SEG_ON,SEG_ON,SEG_OFF,SEG_OFF,SEG_OFF,SEG_OFF],
'j' => [SEG_OFF,SEG_ON,SEG_ON,SEG_ON,SEG_ON,SEG_OFF,SEG_OFF],
'k' => [SEG_OFF,SEG_ON,SEG_ON,SEG_OFF,SEG_ON,SEG_ON,SEG_ON],
'l' => [SEG_OFF,SEG_OFF,SEG_OFF,SEG_ON,SEG_ON,SEG_ON,SEG_OFF],
'm' => [SEG_ON,SEG_OFF,SEG_ON,SEG_OFF,SEG_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ON,SEG_OFF,SEG_OFF,SEG_ON,SEG_ON],
'5' => [SEG_ON,SEG_OFF,SEG_ON,SEG_ON,SEG_OFF,SEG_ON,SEG_ON],
'6' => [SEG_ON,SEG_OFF,SEG_ON,SEG_ON,SEG_ON,SEG_ON,SEG_ON],
'7' => [SEG_ON,SEG_ON,SEG_ON,SEG_OFF,SEG_OFF,SEG_OFF,SEG_OFF],
'8' => [SEG_ON,SEG_ON,SEG_ON,SEG_ON,SEG_ON,SEG_ON,SEG_ON],
'9' => [SEG_ON,SEG_ON,SEG_ON,SEG_ON,SEG_OFF,SEG_ON,SEG_ON],
' ' => [SEG_OFF,SEG_OFF,SEG_OFF,SEG_OFF,SEG_OFF,SEG_OFF,SEG_OFF],
'-' => [SEG_OFF,SEG_OFF,SEG_OFF,SEG_OFF,SEG_OFF,SEG_OFF,SEG_ON],
'_' => [SEG_OFF,SEG_OFF,SEG_OFF,SEG_ON,SEG_OFF,SEG_OFF,SEG_OFF]
]
def shiftOut(dataPin, clockPin, latchPin, bits)
WIO.write( latchPin, LOW )
#firstByte = bits[0,7].reverse.join.to_i(2)
#secondByte = bits[8,15].reverse.join.to_i(2)
bits.each_slice(8) do |slice|
#puts 'Shifting out ' + slice.reverse.join.to_i(2).to_s
Wiringpi.shiftOut(dataPin, clockPin, LSBFIRST, slice.reverse.join.to_i(2))
end
#WIO.write( clockPin, LOW )
#bits.each do |bit|
#
# WIO.write( dataPin, bit )
# WIO.write( clockPin, HIGH )
# WIO.write( clockPin, LOW )
#
#end
WIO.write( latchPin, HIGH )
end
def lcdd(digit,segments)
top = segments[0]
topright = segments[1]
bottomright = segments[2]
bottom = segments[3]
bottomleft = segments[4]
topleft = segments[5]
middle = segments[6]
digit1 = NUM_OFF
digit2 = NUM_OFF
digit3 = NUM_OFF
digit4 = NUM_OFF
digit1 = NUM_ON if digit == 1
digit2 = NUM_ON if digit == 2
digit3 = NUM_ON if digit == 3
digit4 = NUM_ON if digit == 4
lcd(digit1,digit2,digit3,digit4,top,topright,bottomright,bottom,bottomleft,topleft,middle)
end
def lcd(digit1,digit2,digit3,digit4,top,topright,bottomright,bottom,bottomleft,topleft,middle)
shiftOut DATA_PIN, CLOCK_PIN, LATCH_PIN, [digit1,digit2,bottom,bottomleft,digit3,digit4,0,0,topright,middle,top,bottomright,topleft,0,0,0]
end
def shiftOutArray(dataPin, clockPin, latchPin, bits)
Wiringpi.digitalWrite( latchPin, LOW )
bits.each_slice(8) do |slice|
Wiringpi.shiftOut(dataPin, clockPin, LSBFIRST, slice.reverse.join.to_i(2))
end
Wiringpi.digitalWrite( latchPin, HIGH )
end
def charToBits(char)
if @charMap.has_key? char
@charMap[ char ]
else
[SEG_OFF,SEG_OFF,SEG_OFF,SEG_ON,SEG_OFF,SEG_OFF,SEG_OFF]
end
end
while 1
#lcd(NUM_ON,NUM_OFF,NUM_OFF,NUM_OFF,SEG_ON,SEG_ON,SEG_ON,SEG_ON,SEG_ON,SEG_ON,SEG_ON)
if (Time.now - startTime) * 1000 >= 250
message = `uptime` + ' ---- '
charOffset += 1
if charOffset > message.length
charOffset = 1
end
startTime = Time.now
end
(1..4).each do |digit|
letters = message+message
letters = letters[charOffset,charOffset+4]
lcdd digit, charToBits(letters[digit-1])
#puts 'Shifting to digit ' + digit.to_s
sleep 0.001
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.