Class: Led

Inherits:
Object
  • Object
show all
Defined in:
lib/led.rb

Instance Method Summary collapse

Constructor Details

#initializeLed

Returns a new instance of Led.



2
3
4
5
# File 'lib/led.rb', line 2

def initialize
    @color = "000000"
    @zero = "00"
end

Instance Method Details

#get_colorObject



27
28
29
# File 'lib/led.rb', line 27

def get_color
    @color
end

#set_color(value) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/led.rb', line 7

def set_color(value)
    if value < 0
        calc = value.abs.to_s(16).rjust(2,'0')
        calc2 = (255-value.abs).abs.to_s(16).rjust(2,'0')
        @color = @zero+calc2+calc

    elsif value > 0
        calc = value.abs.to_s(16).rjust(2,'0')
        calc2 = (255-value.abs).abs.to_s(16).rjust(2,'0')
        @color = calc + calc2 + @zero

    else
        @color = "00FF00"
    end
end

#stringObject



23
24
25
# File 'lib/led.rb', line 23

def string
    "The LED is #{@color}"
end