Class: Tinkerforge::BrickletRGBLED

Inherits:
Device
  • Object
show all
Defined in:
lib/tinkerforge/bricklet_rgb_led.rb

Overview

Controls one RGB LED

Constant Summary collapse

DEVICE_IDENTIFIER =

:nodoc:

271
DEVICE_DISPLAY_NAME =

:nodoc:

'RGB LED Bricklet'
FUNCTION_SET_RGB_VALUE =

:nodoc:

1
FUNCTION_GET_RGB_VALUE =

:nodoc:

2
FUNCTION_GET_IDENTITY =

:nodoc:

255

Constants inherited from Device

Device::RESPONSE_EXPECTED_ALWAYS_FALSE, Device::RESPONSE_EXPECTED_ALWAYS_TRUE, Device::RESPONSE_EXPECTED_FALSE, Device::RESPONSE_EXPECTED_INVALID_FUNCTION_ID, Device::RESPONSE_EXPECTED_TRUE

Instance Attribute Summary

Attributes inherited from Device

#callback_formats, #expected_response_function_id, #expected_response_sequence_number, #registered_callbacks, #uid

Instance Method Summary collapse

Methods inherited from Device

#dequeue_response, #enqueue_response, #get_api_version, #get_response_expected, #send_request, #set_response_expected, #set_response_expected_all

Constructor Details

#initialize(uid, ipcon) ⇒ BrickletRGBLED

Creates an object with the unique device ID uid and adds it to the IP Connection ipcon.



25
26
27
28
29
30
31
32
33
34
# File 'lib/tinkerforge/bricklet_rgb_led.rb', line 25

def initialize(uid, ipcon)
  super uid, ipcon

  @api_version = [2, 0, 0]

  @response_expected[FUNCTION_SET_RGB_VALUE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_RGB_VALUE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE

end

Instance Method Details

#get_identityObject

Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.

The position can be ‘a’, ‘b’, ‘c’ or ‘d’.

The device identifier numbers can be found :ref:‘here <device_identifier>`. |device_identifier_constant|



54
55
56
# File 'lib/tinkerforge/bricklet_rgb_led.rb', line 54

def get_identity
  send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
end

#get_rgb_valueObject

Returns the rgb value of the LED as set by :func:SetRGBValues.



42
43
44
# File 'lib/tinkerforge/bricklet_rgb_led.rb', line 42

def get_rgb_value
  send_request(FUNCTION_GET_RGB_VALUE, [], '', 3, 'C C C')
end

#set_rgb_value(r, g, b) ⇒ Object

Sets the rgb value for the LED.



37
38
39
# File 'lib/tinkerforge/bricklet_rgb_led.rb', line 37

def set_rgb_value(r, g, b)
  send_request(FUNCTION_SET_RGB_VALUE, [r, g, b], 'C C C', 0, '')
end