Class: Denko::LED::SevenSegment

Inherits:
Object
  • Object
show all
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

Attributes included from Behaviors::MultiPin

#pin, #pins, #proxies

Attributes included from Behaviors::Component

#board

Instance Method Summary collapse

Methods included from Behaviors::MultiPin

#before_initialize, #convert_pins, #proxy_pin, #proxy_states, #require_pin, #require_pins

Methods included from Behaviors::Component

#initialize, #micro_delay

Methods included from Behaviors::State

#initialize, #state

Instance Attribute Details

#segmentsObject (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(options={})
  @segments = [a,b,c,d,e,f,g]
  clear; on
end

#clearObject



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(options={})
  [: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

#offObject



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

Returns:

  • (Boolean)


48
# File 'lib/denko/led/seven_segment.rb', line 48

def off?; !@on; end

#onObject



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

Returns:

  • (Boolean)


47
# File 'lib/denko/led/seven_segment.rb', line 47

def on?;   @on; end