Class: Smalruby::Hardware::NeoPixel
- Inherits:
-
Smalrubot::Components::BaseComponent
- Object
- Smalrubot::Components::BaseComponent
- Smalruby::Hardware::NeoPixel
- Includes:
- Util
- Defined in:
- lib/smalruby/hardware/neo_pixel.rb
Overview
Adafruit NeoPixel RGB LED class
Instance Method Summary collapse
-
#initialize(options) ⇒ NeoPixel
constructor
A new instance of NeoPixel.
-
#set(options) ⇒ Object
set color.
-
#show ⇒ Object
apply color settings.
-
#stop ⇒ Object
destruction.
-
#turn_off ⇒ Object
turn off.
Methods included from Util
osx?, print_exception, process_options, raspberrypi?, windows?
Constructor Details
#initialize(options) ⇒ NeoPixel
Returns a new instance of NeoPixel.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/smalruby/hardware/neo_pixel.rb', line 11 def initialize() pin = Pin.smalruby_to_smalrubot([: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 |
Instance Method Details
#set(options) ⇒ Object
set color
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/smalruby/hardware/neo_pixel.rb', line 23 def set() defaults = { index: 0, color: "black", show: true, } opts = (, 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 ⇒ Object
apply color settings
39 40 41 |
# File 'lib/smalruby/hardware/neo_pixel.rb', line 39 def show board.show_neo_pixel end |
#stop ⇒ Object
destruction
54 55 56 57 58 59 |
# File 'lib/smalruby/hardware/neo_pixel.rb', line 54 def stop if @indexes.length > 0 turn_off @indexes.clear end end |
#turn_off ⇒ Object
turn off
44 45 46 47 48 49 50 51 |
# File 'lib/smalruby/hardware/neo_pixel.rb', line 44 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 |