Sha256: 80ec98b44819b942488871a33a3b1c6e5f801ead21000ed036e3b890351499a7
Contents?: true
Size: 1.45 KB
Versions: 20
Compression:
Stored size: 1.45 KB
Contents
# -*- coding: utf-8 -*- require 'smalruby/hardware' module Smalruby module Hardware # RGB LED(アノード)を表現するクラス class RgbLedAnode < Dino::Components::BaseComponent def initialize(options) pin = Pin.smalruby_to_dino(options[:pin]) case pin when 3..6 super(board: world.board, pin: [3, 5, 6, 4]) when 9..12 super(board: world.board, pin: [9, 10, 11, 12]) else fail "RGB LED(anode)のピン番号が間違っています: {options[:pin]}" end end # RGB LEDをオンにする def on(options = {}) defaults = { color: 'white' } opts = Util.process_options(options, defaults) color = Color.smalruby_to_dxruby(opts[:color]) analog_write(pins[0], calc_value(color[0])) analog_write(pins[1], calc_value(color[1])) analog_write(pins[2], calc_value(color[2])) digital_write(pins[3], Dino::Board::HIGH) end # RGB LEDをオフにする def off digital_write(pins[3], Dino::Board::LOW) end private def after_initialize(options = {}) set_pin_mode(pins[3], :out) off end def calc_value(value) v = Dino::Board::HIGH - value if v < Dino::Board::LOW Dino::Board::LOW elsif v > Dino::Board::HIGH Dino::Board::HIGH else v end end end end end
Version data entries
20 entries across 20 versions & 1 rubygems