Class: Denko::LED::SevenSegment
- Inherits:
-
Object
- Object
- Denko::LED::SevenSegment
- Includes:
- Behaviors::MultiPin
- Defined in:
- lib/denko/led/seven_segment.rb
Constant Summary collapse
- ALL_OFF =
[0,0,0,0,0,0,0]
- BLANK =
" "
- 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(string) ⇒ Object
- #initialize_pins(options = {}) ⇒ Object
- #off ⇒ Object
- #off? ⇒ Boolean
- #on ⇒ Object
- #on? ⇒ Boolean
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.
23 24 25 |
# File 'lib/denko/led/seven_segment.rb', line 23 def segments @segments end |
Instance Method Details
#after_initialize(options = {}) ⇒ Object
18 19 20 21 |
# File 'lib/denko/led/seven_segment.rb', line 18 def after_initialize(={}) @segments = [a,b,c,d,e,f,g] clear; on end |
#clear ⇒ Object
25 26 27 |
# File 'lib/denko/led/seven_segment.rb', line 25 def clear write(BLANK) end |
#display(string) ⇒ Object
29 30 31 32 33 |
# File 'lib/denko/led/seven_segment.rb', line 29 def display(string) on unless on? string = string.to_s.upcase (string.length > 1) ? scroll(string) : write(string) end |
#initialize_pins(options = {}) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/denko/led/seven_segment.rb', line 9 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
41 42 43 44 45 |
# File 'lib/denko/led/seven_segment.rb', line 41 def off anode.low if anode cathode.high if cathode @on = false end |
#off? ⇒ Boolean
48 |
# File 'lib/denko/led/seven_segment.rb', line 48 def off?; !@on; end |
#on ⇒ Object
35 36 37 38 39 |
# File 'lib/denko/led/seven_segment.rb', line 35 def on anode.high if anode cathode.low if cathode @on = true end |
#on? ⇒ Boolean
47 |
# File 'lib/denko/led/seven_segment.rb', line 47 def on?; @on; end |