Class: Denko::LED::SevenSegment
- Inherits:
-
Object
- Object
- Denko::LED::SevenSegment
- Includes:
- Behaviors::MultiPin
- Defined in:
- lib/denko/led/seven_segment.rb
Constant Summary collapse
- CHARACTERS =
{ '0' => [1,1,1,1,1,1,0], '1' => [0,1,1,0,0,0,0], '2' => [1,1,0,1,1,0,1], '3' => [1,1,1,1,0,0,1], '4' => [0,1,1,0,0,1,1], '5' => [1,0,1,1,0,1,1], '6' => [1,0,1,1,1,1,1], '7' => [1,1,1,0,0,0,0], '8' => [1,1,1,1,1,1,1], '9' => [1,1,1,1,0,1,1], ' ' => [0,0,0,0,0,0,0], '_' => [0,0,0,1,0,0,0], '-' => [0,0,0,0,0,0,1], 'A' => [1,1,1,0,1,1,1], 'B' => [0,0,1,1,1,1,1], 'C' => [0,0,0,1,1,0,1], 'D' => [0,1,1,1,1,0,1], 'E' => [1,0,0,1,1,1,1], 'F' => [1,0,0,0,1,1,1], 'G' => [1,0,1,1,1,1,0], 'H' => [0,0,1,0,1,1,1], 'I' => [0,0,1,0,0,0,0], 'J' => [0,1,1,1,1,0,0], 'K' => [1,0,1,0,1,1,1], 'L' => [0,0,0,1,1,1,0], 'M' => [1,1,1,0,1,1,0], 'N' => [0,0,1,0,1,0,1], 'O' => [0,0,1,1,1,0,1], 'P' => [1,1,0,0,1,1,1], 'Q' => [1,1,1,0,0,1,1], 'R' => [0,0,0,0,1,0,1], 'S' => [1,0,1,1,0,1,1], 'T' => [0,0,0,1,1,1,1], 'U' => [0,0,1,1,1,0,0], 'V' => [0,1,1,1,1,1,0], 'W' => [0,1,1,1,1,1,1], 'X' => [0,1,1,0,1,1,1], 'Y' => [0,1,1,1,0,1,1], 'Z' => [1,1,0,1,1,0,0], }
Instance Attribute Summary collapse
-
#segments ⇒ Object
readonly
Returns the value of attribute segments.
Attributes included from Behaviors::MultiPin
Attributes included from Behaviors::Component
Instance Method Summary collapse
- #after_initialize(options = {}) ⇒ Object
- #clear ⇒ Object
- #display(char) ⇒ Object
- #initialize_pins(options = {}) ⇒ Object
- #off ⇒ Object
- #on ⇒ Object
Methods included from Behaviors::MultiPin
#before_initialize, #convert_pins, #proxy_pin, #proxy_states, #require_pin, #require_pins
Methods included from Behaviors::Component
Methods included from Behaviors::State
Instance Attribute Details
#segments ⇒ Object (readonly)
Returns the value of attribute segments.
20 21 22 |
# File 'lib/denko/led/seven_segment.rb', line 20 def segments @segments end |
Instance Method Details
#after_initialize(options = {}) ⇒ Object
15 16 17 18 |
# File 'lib/denko/led/seven_segment.rb', line 15 def after_initialize(={}) @segments = [a,b,c,d,e,f,g] clear; on end |
#clear ⇒ Object
22 23 24 25 26 27 |
# File 'lib/denko/led/seven_segment.rb', line 22 def clear segments.each do |pin| pin.low if cathode pin.high if anode end end |
#display(char) ⇒ Object
29 30 31 32 33 |
# File 'lib/denko/led/seven_segment.rb', line 29 def display(char) char = char.to_s return scroll(char) if char.length > 1 off; write(char); on end |
#initialize_pins(options = {}) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/denko/led/seven_segment.rb', line 6 def initialize_pins(={}) [:a, :b, :c, :d, :e, :f, :g].each do |symbol| proxy_pin(symbol, DigitalIO::Output) end proxy_pin :cathode, DigitalIO::Output, optional: true proxy_pin :anode, DigitalIO::Output, optional: true end |
#off ⇒ Object
40 41 42 43 |
# File 'lib/denko/led/seven_segment.rb', line 40 def off anode.low if anode cathode.high if cathode end |
#on ⇒ Object
35 36 37 38 |
# File 'lib/denko/led/seven_segment.rb', line 35 def on anode.high if anode cathode.low if cathode end |