Class: Ledstrip::Effects::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ledstrip/effects/base.rb

Direct Known Subclasses

FullColor, Rainbow, Random

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(strip, options = {}) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
12
# File 'lib/ledstrip/effects/base.rb', line 7

def initialize(strip, options = {})
  @strip = strip
  @options = options
  @running = false
  @frame = 1 
end

Instance Attribute Details

#runningObject

Returns the value of attribute running.



5
6
7
# File 'lib/ledstrip/effects/base.rb', line 5

def running
  @running
end

Instance Method Details

#runObject



33
34
35
36
37
38
39
40
# File 'lib/ledstrip/effects/base.rb', line 33

def run
  Thread.new do
    while(running) do
      tick
      sleep sleep_time
    end
  end
end

#sleep_timeObject



14
15
16
# File 'lib/ledstrip/effects/base.rb', line 14

def sleep_time
  1
end

#startObject



18
19
20
21
# File 'lib/ledstrip/effects/base.rb', line 18

def start
  @running = true
  run
end

#stopObject



23
24
25
# File 'lib/ledstrip/effects/base.rb', line 23

def stop
  @running = false
end

#tickObject



27
28
29
30
31
# File 'lib/ledstrip/effects/base.rb', line 27

def tick
  @strip.leds = step(@strip.leds)
  @strip.draw
  @frame += 1
end