class Smalruby::Hardware::NeoPixel
Adafruit NeoPixel
RGB LED class
Public Class Methods
new(options)
click to toggle source
Calls superclass method
# File lib/smalruby/hardware/neo_pixel.rb, line 10 def initialize(options) pin = Pin.smalruby_to_smalrubot(options[:pin]) case pin when 3, 5, 6, 9, 10, 11 super(board: world.board, pin: pin) else fail "ピン番号が間違っています: {options[:pin]}" end @indexes = Set.new end
Public Instance Methods
set(options)
click to toggle source
set color
# File lib/smalruby/hardware/neo_pixel.rb, line 22 def set(options) defaults = { index: 0, color: "black", show: true, } opts = process_options(options, defaults) @indexes << opts[:index] color = Color.smalruby_to_dxruby(opts[:color]) board.set_neo_pixel_color(opts[:index], *color) if opts[:show] show end end
show()
click to toggle source
apply color settings
# File lib/smalruby/hardware/neo_pixel.rb, line 38 def show board.show_neo_pixel end
stop()
click to toggle source
destruction
# File lib/smalruby/hardware/neo_pixel.rb, line 53 def stop if @indexes.length > 0 turn_off @indexes.clear end end
turn_off()
click to toggle source
turn off
# File lib/smalruby/hardware/neo_pixel.rb, line 43 def turn_off if @indexes.length > 0 @indexes.each do |i| board.set_neo_pixel_color(i, 0, 0, 0) end board.show_neo_pixel end end
Private Instance Methods
after_initialize(_ = {})
click to toggle source
# File lib/smalruby/hardware/neo_pixel.rb, line 62 def after_initialize(_ = {}) board.set_neo_pixel_pin(pin) board.show_neo_pixel end