Class: Denko::LED::SevenSegment

Inherits:
Object
  • Object
show all
Includes:
Behaviors::Lifecycle, 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],
}

Constants included from Behaviors::Lifecycle

Behaviors::Lifecycle::CALLBACK_METHODS

Instance Attribute Summary

Attributes included from Behaviors::MultiPin

#pin, #pins, #proxies

Attributes included from Behaviors::Component

#board, #params

Attributes included from Behaviors::State

#state

Instance Method Summary collapse

Methods included from Behaviors::Lifecycle

included

Methods included from Behaviors::MultiPin

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

Methods included from Behaviors::Component

#initialize, #micro_delay

Methods included from Behaviors::State

#update_state

Instance Method Details

#clearObject



28
29
30
# File 'lib/denko/led/seven_segment.rb', line 28

def clear
  write(BLANK)
end

#display(string) ⇒ Object



32
33
34
35
36
# File 'lib/denko/led/seven_segment.rb', line 32

def display(string)
  on unless on?
  string = string.to_s.upcase
  (string.length > 1) ? scroll(string) : write(string)
end

#initialize_pins(options = {}) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/denko/led/seven_segment.rb', line 10

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



44
45
46
47
48
# File 'lib/denko/led/seven_segment.rb', line 44

def off
  anode.low if anode
  cathode.high if cathode
  @on = false
end

#off?Boolean

Returns:

  • (Boolean)


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

def off?; !@on; end

#onObject



38
39
40
41
42
# File 'lib/denko/led/seven_segment.rb', line 38

def on
  anode.high if anode
  cathode.low if cathode
  @on = true
end

#on?Boolean

Returns:

  • (Boolean)


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

def on?;   @on; end

#segmentsObject



19
20
21
# File 'lib/denko/led/seven_segment.rb', line 19

def segments
  @segments ||= [a,b,c,d,e,f,g]
end