Class: Time7Segment
- Inherits:
-
Object
- Object
- Time7Segment
- Defined in:
- lib/time7segment.rb
Instance Method Summary collapse
-
#initialize(gpio = %w(22 27 17 24 11 4 23 8 20 10 18 25),, refresh: 0.005) ⇒ Time7Segment
constructor
d1 d2 d3 d4 a b c d e f g dp.
- #start ⇒ Object
Constructor Details
#initialize(gpio = %w(22 27 17 24 11 4 23 8 20 10 18 25),, refresh: 0.005) ⇒ Time7Segment
d1 d2 d3 d4 a b c d e f g dp
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/time7segment.rb', line 31 def initialize(gpio=%w(22 27 17 24 11 4 23 8 20 10 18 25), refresh: 0.005) pins = SimpleRaspberryPi.new(gpio).pins @digits, @segments, @refresh = pins.take(4), pins.slice(4..-1), refresh a = [0x7E, 0x30, 0x6D, 0x79, 0x33, 0x5B, 0x5F, 0x70, 0x7F, 0x7B] @numerals = a.map do |x| x.to_s(2).rjust(7,'0').chars.map {|x| x == '1' ? :off : :on } end end |
Instance Method Details
#start ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/time7segment.rb', line 44 def start loop do Time.now.strftime("%H%M").chars.each.with_index do |x,i| n = x.to_i display(n); @segments[7].method( i == 1 ? :off : :on).call @digits[i].on refresh = @refresh # reduce the sleep time for digit 1 since it takes less time to # update the segments. This gives a more balanced brightness display, # especially for digits 0 and 8 refresh -= refresh / 2 if n == 1 sleep refresh @digits[i].off end end end |