Sha256: b18e6bcab7cf6e0d06b381a49a1543d9dcbd7e506087de8babb2c127fba69405

Contents?: true

Size: 766 Bytes

Versions: 4

Compression:

Stored size: 766 Bytes

Contents

require 'color'

require "extreme_feedback_device/spi"

module ExtremeFeedbackDevice
  class Pi
    attr_reader :leds

    def initialize(num_leds, spi_device=nil)
      @leds = []
      num_leds.times { @leds << ::Color::RGB.new }
      @spi_device = spi_device
    end

    def leds_white
      leds.map! { |led| ::Color::RGB::White }
    end

    def leds_white!
      leds_white && write!
    end

    def leds_black
      leds.map! { |led| ::Color::RGB::Black }
    end

    def leds_black!
      leds_black && write!
    end

    def write!
      spi.write_colors(colors)
    end

  private

    def spi
      @spi ||= ExtremeFeedbackDevice::SPI.new(@spi_device)
    end

    def colors
      leds.map { |led| [led.red, led.green, led.blue] }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
extreme_feedback_device-0.0.4 lib/extreme_feedback_device/pi.rb
extreme_feedback_device-0.0.3 lib/extreme_feedback_device/pi.rb
extreme_feedback_device-0.0.2 lib/extreme_feedback_device/pi.rb
extreme_feedback_device-0.0.1 lib/extreme_feedback_device/pi.rb