Class: Tinkerforge::BrickletLEDStripV2
- Defined in:
- lib/tinkerforge/bricklet_led_strip_v2.rb
Overview
Controls up to 2048 RGB(W) LEDs
Constant Summary collapse
- DEVICE_IDENTIFIER =
:nodoc:
2103
- DEVICE_DISPLAY_NAME =
:nodoc:
'LED Strip Bricklet 2.0'
- CALLBACK_FRAME_STARTED =
This callback is triggered directly after a new frame render is started. The parameter is the number of LEDs in that frame.
You should send the data for the next frame directly after this callback was triggered.
For an explanation of the general approach see BrickletLEDStripV2#set_led_values.
6
- FUNCTION_SET_LED_VALUES_LOW_LEVEL =
:nodoc:
1
- FUNCTION_GET_LED_VALUES_LOW_LEVEL =
:nodoc:
2
- FUNCTION_SET_FRAME_DURATION =
:nodoc:
3
- FUNCTION_GET_FRAME_DURATION =
:nodoc:
4
- FUNCTION_GET_SUPPLY_VOLTAGE =
:nodoc:
5
- FUNCTION_SET_CLOCK_FREQUENCY =
:nodoc:
7
- FUNCTION_GET_CLOCK_FREQUENCY =
:nodoc:
8
- FUNCTION_SET_CHIP_TYPE =
:nodoc:
9
- FUNCTION_GET_CHIP_TYPE =
:nodoc:
10
- FUNCTION_SET_CHANNEL_MAPPING =
:nodoc:
11
- FUNCTION_GET_CHANNEL_MAPPING =
:nodoc:
12
- FUNCTION_SET_FRAME_STARTED_CALLBACK_CONFIGURATION =
:nodoc:
13
- FUNCTION_GET_FRAME_STARTED_CALLBACK_CONFIGURATION =
:nodoc:
14
- FUNCTION_GET_SPITFP_ERROR_COUNT =
:nodoc:
234
- FUNCTION_SET_BOOTLOADER_MODE =
:nodoc:
235
- FUNCTION_GET_BOOTLOADER_MODE =
:nodoc:
236
- FUNCTION_SET_WRITE_FIRMWARE_POINTER =
:nodoc:
237
- FUNCTION_WRITE_FIRMWARE =
:nodoc:
238
- FUNCTION_SET_STATUS_LED_CONFIG =
:nodoc:
239
- FUNCTION_GET_STATUS_LED_CONFIG =
:nodoc:
240
- FUNCTION_GET_CHIP_TEMPERATURE =
:nodoc:
242
- FUNCTION_RESET =
:nodoc:
243
- FUNCTION_WRITE_UID =
:nodoc:
248
- FUNCTION_READ_UID =
:nodoc:
249
- FUNCTION_GET_IDENTITY =
:nodoc:
255
- CHIP_TYPE_WS2801 =
:nodoc:
2801
- CHIP_TYPE_WS2811 =
:nodoc:
2811
- CHIP_TYPE_WS2812 =
:nodoc:
2812
- CHIP_TYPE_LPD8806 =
:nodoc:
8806
- CHIP_TYPE_APA102 =
:nodoc:
102
- CHANNEL_MAPPING_RGB =
:nodoc:
6
- CHANNEL_MAPPING_RBG =
:nodoc:
9
- CHANNEL_MAPPING_BRG =
:nodoc:
33
- CHANNEL_MAPPING_BGR =
:nodoc:
36
- CHANNEL_MAPPING_GRB =
:nodoc:
18
- CHANNEL_MAPPING_GBR =
:nodoc:
24
- CHANNEL_MAPPING_RGBW =
:nodoc:
27
- CHANNEL_MAPPING_RGWB =
:nodoc:
30
- CHANNEL_MAPPING_RBGW =
:nodoc:
39
- CHANNEL_MAPPING_RBWG =
:nodoc:
45
- CHANNEL_MAPPING_RWGB =
:nodoc:
54
- CHANNEL_MAPPING_RWBG =
:nodoc:
57
- CHANNEL_MAPPING_GRWB =
:nodoc:
78
- CHANNEL_MAPPING_GRBW =
:nodoc:
75
- CHANNEL_MAPPING_GBWR =
:nodoc:
108
- CHANNEL_MAPPING_GBRW =
:nodoc:
99
- CHANNEL_MAPPING_GWBR =
:nodoc:
120
- CHANNEL_MAPPING_GWRB =
:nodoc:
114
- CHANNEL_MAPPING_BRGW =
:nodoc:
135
- CHANNEL_MAPPING_BRWG =
:nodoc:
141
- CHANNEL_MAPPING_BGRW =
:nodoc:
147
- CHANNEL_MAPPING_BGWR =
:nodoc:
156
- CHANNEL_MAPPING_BWRG =
:nodoc:
177
- CHANNEL_MAPPING_BWGR =
:nodoc:
180
- CHANNEL_MAPPING_WRBG =
:nodoc:
201
- CHANNEL_MAPPING_WRGB =
:nodoc:
198
- CHANNEL_MAPPING_WGBR =
:nodoc:
216
- CHANNEL_MAPPING_WGRB =
:nodoc:
210
- CHANNEL_MAPPING_WBGR =
:nodoc:
228
- CHANNEL_MAPPING_WBRG =
:nodoc:
225
- BOOTLOADER_MODE_BOOTLOADER =
:nodoc:
0
- BOOTLOADER_MODE_FIRMWARE =
:nodoc:
1
- BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT =
:nodoc:
2
- BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT =
:nodoc:
3
- BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT =
:nodoc:
4
- BOOTLOADER_STATUS_OK =
:nodoc:
0
- BOOTLOADER_STATUS_INVALID_MODE =
:nodoc:
1
- BOOTLOADER_STATUS_NO_CHANGE =
:nodoc:
2
- BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT =
:nodoc:
3
- BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT =
:nodoc:
4
- BOOTLOADER_STATUS_CRC_MISMATCH =
:nodoc:
5
- STATUS_LED_CONFIG_OFF =
:nodoc:
0
- STATUS_LED_CONFIG_ON =
:nodoc:
1
- STATUS_LED_CONFIG_SHOW_HEARTBEAT =
:nodoc:
2
- STATUS_LED_CONFIG_SHOW_STATUS =
:nodoc:
3
Constants inherited from Device
Device::DEVICE_IDENTIFIER_CHECK_MATCH, Device::DEVICE_IDENTIFIER_CHECK_MISMATCH, Device::DEVICE_IDENTIFIER_CHECK_PENDING, 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, #high_level_callbacks, #registered_callbacks, #replaced, #uid
Instance Method Summary collapse
-
#get_bootloader_mode ⇒ Object
Returns the current bootloader mode, see BrickletLEDStripV2#set_bootloader_mode.
-
#get_channel_mapping ⇒ Object
Returns the currently used channel mapping as set by BrickletLEDStripV2#set_channel_mapping.
-
#get_chip_temperature ⇒ Object
Returns the temperature as measured inside the microcontroller.
-
#get_chip_type ⇒ Object
Returns the currently used chip type as set by BrickletLEDStripV2#set_chip_type.
-
#get_clock_frequency ⇒ Object
Returns the currently used clock frequency as set by BrickletLEDStripV2#set_clock_frequency.
-
#get_frame_duration ⇒ Object
Returns the frame duration as set by BrickletLEDStripV2#set_frame_duration.
-
#get_frame_started_callback_configuration ⇒ Object
Returns the configuration as set by BrickletLEDStripV2#set_frame_started_callback_configuration.
-
#get_identity ⇒ Object
Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.
-
#get_led_values(index, length) ⇒ Object
Returns length RGB(W) values starting from the given index.
-
#get_led_values_low_level(index, length) ⇒ Object
Returns length RGB(W) values starting from the given index.
-
#get_spitfp_error_count ⇒ Object
Returns the error count for the communication between Brick and Bricklet.
-
#get_status_led_config ⇒ Object
Returns the configuration as set by BrickletLEDStripV2#set_status_led_config.
-
#get_supply_voltage ⇒ Object
Returns the current supply voltage of the LEDs.
-
#initialize(uid, ipcon) ⇒ BrickletLEDStripV2
constructor
Creates an object with the unique device ID
uid
and adds it to the IP Connectionipcon
. -
#read_uid ⇒ Object
Returns the current UID as an integer.
-
#register_callback(id, &block) ⇒ Object
Registers a callback with ID
id
to the blockblock
. -
#reset ⇒ Object
Calling this function will reset the Bricklet.
-
#set_bootloader_mode(mode) ⇒ Object
Sets the bootloader mode and returns the status after the requested mode change was instigated.
-
#set_channel_mapping(mapping) ⇒ Object
Sets the channel mapping for the connected LEDs.
-
#set_chip_type(chip) ⇒ Object
Sets the type of the LED driver chip.
-
#set_clock_frequency(frequency) ⇒ Object
Sets the frequency of the clock.
-
#set_frame_duration(duration) ⇒ Object
Sets the frame duration.
-
#set_frame_started_callback_configuration(enable) ⇒ Object
Enables/disables the CALLBACK_FRAME_STARTED callback.
-
#set_led_values(index, value) ⇒ Object
Sets the RGB(W) values for the LEDs starting from index.
-
#set_led_values_low_level(index, value_length, value_chunk_offset, value_chunk_data) ⇒ Object
Sets the RGB(W) values for the LEDs starting from index.
-
#set_status_led_config(config) ⇒ Object
Sets the status LED configuration.
-
#set_write_firmware_pointer(pointer) ⇒ Object
Sets the firmware pointer for BrickletLEDStripV2#write_firmware.
-
#write_firmware(data) ⇒ Object
Writes 64 Bytes of firmware at the position as written by BrickletLEDStripV2#set_write_firmware_pointer before.
-
#write_uid(uid) ⇒ Object
Writes a new UID into flash.
Methods inherited from Device
#check_validity, #dequeue_response, #enqueue_response, #get_api_version, #get_response_expected, #send_request, #set_response_expected, #set_response_expected_all
Constructor Details
#initialize(uid, ipcon) ⇒ BrickletLEDStripV2
Creates an object with the unique device ID uid
and adds it to the IP Connection ipcon
.
Instance Method Details
#get_bootloader_mode ⇒ Object
Returns the current bootloader mode, see BrickletLEDStripV2#set_bootloader_mode.
339 340 341 342 343 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 339 def get_bootloader_mode check_validity send_request FUNCTION_GET_BOOTLOADER_MODE, [], '', 9, 'C' end |
#get_channel_mapping ⇒ Object
Returns the currently used channel mapping as set by BrickletLEDStripV2#set_channel_mapping.
285 286 287 288 289 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 285 def get_channel_mapping check_validity send_request FUNCTION_GET_CHANNEL_MAPPING, [], '', 9, 'C' end |
#get_chip_temperature ⇒ Object
Returns the temperature as measured inside the microcontroller. The value returned is not the ambient temperature!
The temperature is only proportional to the real temperature and it has bad accuracy. Practically it is only useful as an indicator for temperature changes.
397 398 399 400 401 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 397 def get_chip_temperature check_validity send_request FUNCTION_GET_CHIP_TEMPERATURE, [], '', 10, 's' end |
#get_chip_type ⇒ Object
Returns the currently used chip type as set by BrickletLEDStripV2#set_chip_type.
257 258 259 260 261 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 257 def get_chip_type check_validity send_request FUNCTION_GET_CHIP_TYPE, [], '', 10, 'S' end |
#get_clock_frequency ⇒ Object
Returns the currently used clock frequency as set by BrickletLEDStripV2#set_clock_frequency.
235 236 237 238 239 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 235 def get_clock_frequency check_validity send_request FUNCTION_GET_CLOCK_FREQUENCY, [], '', 12, 'L' end |
#get_frame_duration ⇒ Object
Returns the frame duration as set by BrickletLEDStripV2#set_frame_duration.
203 204 205 206 207 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 203 def get_frame_duration check_validity send_request FUNCTION_GET_FRAME_DURATION, [], '', 10, 'S' end |
#get_frame_started_callback_configuration ⇒ Object
Returns the configuration as set by BrickletLEDStripV2#set_frame_started_callback_configuration.
300 301 302 303 304 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 300 def get_frame_started_callback_configuration check_validity send_request FUNCTION_GET_FRAME_STARTED_CALLBACK_CONFIGURATION, [], '', 9, '?' end |
#get_identity ⇒ Object
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’, ‘d’, ‘e’, ‘f’, ‘g’ or ‘h’ (Bricklet Port). A Bricklet connected to an :ref:‘Isolator Bricklet <isolator_bricklet>` is always at position ’z’.
The device identifier numbers can be found :ref:‘here <device_identifier>`. |device_identifier_constant|
444 445 446 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 444 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end |
#get_led_values(index, length) ⇒ Object
Returns length RGB(W) values starting from the given index.
If the channel mapping has 3 colors, you will get the data in the sequence RGBRGBRGB… if the channel mapping has 4 colors you will get the data in the sequence RGBWRGBWRGBW… (assuming you start at an index divisible by 3 (RGB) or 4 (RGBW)).
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 511 def get_led_values(index, length) value_length = nil # assigned in block value_data = nil # assigned in block @stream_mutex.synchronize { ret = get_led_values_low_level index, length value_length = ret[0] value_chunk_offset = ret[1] value_out_of_sync = value_chunk_offset != 0 value_data = ret[2] while not value_out_of_sync and value_data.length < value_length ret = get_led_values_low_level index, length value_length = ret[0] value_chunk_offset = ret[1] value_out_of_sync = value_chunk_offset != value_data.length value_data += ret[2] end if value_out_of_sync # discard remaining stream to bring it back in-sync while value_chunk_offset + 60 < value_length ret = get_led_values_low_level index, length value_length = ret[0] value_chunk_offset = ret[1] end raise StreamOutOfSyncException, 'Value stream is out-of-sync' end } value_data[0, value_length] end |
#get_led_values_low_level(index, length) ⇒ Object
Returns length RGB(W) values starting from the given index.
If the channel mapping has 3 colors, you will get the data in the sequence RGBRGBRGB… if the channel mapping has 4 colors you will get the data in the sequence RGBWRGBWRGBW… (assuming you start at an index divisible by 3 (RGB) or 4 (RGBW)).
182 183 184 185 186 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 182 def get_led_values_low_level(index, length) check_validity send_request FUNCTION_GET_LED_VALUES_LOW_LEVEL, [index, length], 'S S', 72, 'S S C60' end |
#get_spitfp_error_count ⇒ Object
Returns the error count for the communication between Brick and Bricklet.
The errors are divided into
-
ACK checksum errors,
-
message checksum errors,
-
framing errors and
-
overflow errors.
The errors counts are for errors that occur on the Bricklet side. All Bricks have a similar function that returns the errors on the Brick side.
317 318 319 320 321 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 317 def get_spitfp_error_count check_validity send_request FUNCTION_GET_SPITFP_ERROR_COUNT, [], '', 24, 'L L L L' end |
#get_status_led_config ⇒ Object
Returns the configuration as set by BrickletLEDStripV2#set_status_led_config
385 386 387 388 389 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 385 def get_status_led_config check_validity send_request FUNCTION_GET_STATUS_LED_CONFIG, [], '', 9, 'C' end |
#get_supply_voltage ⇒ Object
Returns the current supply voltage of the LEDs.
210 211 212 213 214 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 210 def get_supply_voltage check_validity send_request FUNCTION_GET_SUPPLY_VOLTAGE, [], '', 10, 'S' end |
#read_uid ⇒ Object
Returns the current UID as an integer. Encode as Base58 to get the usual string version.
428 429 430 431 432 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 428 def read_uid check_validity send_request FUNCTION_READ_UID, [], '', 12, 'L' end |
#register_callback(id, &block) ⇒ Object
Registers a callback with ID id
to the block block
.
545 546 547 548 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 545 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end |
#reset ⇒ Object
Calling this function will reset the Bricklet. All configurations will be lost.
After a reset you have to create new device objects, calling functions on the existing ones will result in undefined behavior!
409 410 411 412 413 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 409 def reset check_validity send_request FUNCTION_RESET, [], '', 8, '' end |
#set_bootloader_mode(mode) ⇒ Object
Sets the bootloader mode and returns the status after the requested mode change was instigated.
You can change from bootloader mode to firmware mode and vice versa. A change from bootloader mode to firmware mode will only take place if the entry function, device identifier and CRC are present and correct.
This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.
332 333 334 335 336 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 332 def set_bootloader_mode(mode) check_validity send_request FUNCTION_SET_BOOTLOADER_MODE, [mode], 'C', 9, 'C' end |
#set_channel_mapping(mapping) ⇒ Object
Sets the channel mapping for the connected LEDs.
If the mapping has 4 colors, the function BrickletLEDStripV2#set_led_values expects 4 values per pixel and if the mapping has 3 colors it expects 3 values per pixel.
The function always expects the order RGB(W). The connected LED driver chips might have their 3 or 4 channels in a different order. For example, the WS2801 chips typically use BGR order, then WS2812 chips typically use GRB order and the APA102 chips typically use WBGR order.
The APA102 chips are special. They have three 8-bit channels for RGB and an additional 5-bit channel for the overall brightness of the RGB LED making them 4-channel chips. Internally the brightness channel is the first channel, therefore one of the Wxyz channel mappings should be used. Then the W channel controls the brightness.
278 279 280 281 282 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 278 def set_channel_mapping(mapping) check_validity send_request FUNCTION_SET_CHANNEL_MAPPING, [mapping], 'C', 8, '' end |
#set_chip_type(chip) ⇒ Object
Sets the type of the LED driver chip. We currently support the chips
-
WS2801,
-
WS2811,
-
WS2812 / SK6812 / NeoPixel RGB,
-
SK6812RGBW / NeoPixel RGBW (Chip Type = WS2812),
-
WS2813 / WS2815 (Chip Type = WS2812)
-
LPD8806 and
-
APA102 / DotStar.
250 251 252 253 254 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 250 def set_chip_type(chip) check_validity send_request FUNCTION_SET_CHIP_TYPE, [chip], 'S', 8, '' end |
#set_clock_frequency(frequency) ⇒ Object
Sets the frequency of the clock.
The Bricklet will choose the nearest achievable frequency, which may be off by a few Hz. You can get the exact frequency that is used by calling BrickletLEDStripV2#get_clock_frequency.
If you have problems with flickering LEDs, they may be bits flipping. You can fix this by either making the connection between the LEDs and the Bricklet shorter or by reducing the frequency.
With a decreasing frequency your maximum frames per second will decrease too.
228 229 230 231 232 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 228 def set_clock_frequency(frequency) check_validity send_request FUNCTION_SET_CLOCK_FREQUENCY, [frequency], 'L', 8, '' end |
#set_frame_duration(duration) ⇒ Object
Sets the frame duration.
Example: If you want to achieve 20 frames per second, you should set the frame duration to 50ms (50ms * 20 = 1 second).
For an explanation of the general approach see BrickletLEDStripV2#set_led_values.
Default value: 100ms (10 frames per second).
196 197 198 199 200 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 196 def set_frame_duration(duration) check_validity send_request FUNCTION_SET_FRAME_DURATION, [duration], 'S', 8, '' end |
#set_frame_started_callback_configuration(enable) ⇒ Object
Enables/disables the CALLBACK_FRAME_STARTED callback.
292 293 294 295 296 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 292 def set_frame_started_callback_configuration(enable) check_validity send_request FUNCTION_SET_FRAME_STARTED_CALLBACK_CONFIGURATION, [enable], '?', 8, '' end |
#set_led_values(index, value) ⇒ Object
Sets the RGB(W) values for the LEDs starting from index. You can set at most 2048 RGB values or 1536 RGBW values (6144 byte each).
To make the colors show correctly you need to configure the chip type (see BrickletLEDStripV2#set_chip_type) and a channel mapping (see BrickletLEDStripV2#set_channel_mapping) according to the connected LEDs.
If the channel mapping has 3 colors, you need to give the data in the sequence RGBRGBRGB… if the channel mapping has 4 colors you need to give data in the sequence RGBWRGBWRGBW…
The data is double buffered and the colors will be transfered to the LEDs when the next frame duration ends (see BrickletLEDStripV2#set_frame_duration).
Generic approach:
-
Set the frame duration to a value that represents the number of frames per second you want to achieve.
-
Set all of the LED colors for one frame.
-
Wait for the CALLBACK_FRAME_STARTED callback.
-
Set all of the LED colors for next frame.
-
Wait for the CALLBACK_FRAME_STARTED callback.
-
And so on.
This approach ensures that you can change the LED colors with a fixed frame rate.
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 473 def set_led_values(index, value) if value.length > 65535 raise ArgumentError, 'Value can be at most 65535 items long' end value_length = value.length value_chunk_offset = 0 if value_length == 0 value_chunk_data = [0] * 58 ret = set_led_values_low_level index, value_length, value_chunk_offset, value_chunk_data else ret = nil # assigned in block @stream_mutex.synchronize { while value_chunk_offset < value_length value_chunk_data = value[value_chunk_offset, 58] if value_chunk_data.length < 58 value_chunk_data += [0] * (58 - value_chunk_data.length) end ret = set_led_values_low_level index, value_length, value_chunk_offset, value_chunk_data value_chunk_offset += 58 end } end ret end |
#set_led_values_low_level(index, value_length, value_chunk_offset, value_chunk_data) ⇒ Object
Sets the RGB(W) values for the LEDs starting from index. You can set at most 2048 RGB values or 1536 RGBW values (6144 byte each).
To make the colors show correctly you need to configure the chip type (see BrickletLEDStripV2#set_chip_type) and a channel mapping (see BrickletLEDStripV2#set_channel_mapping) according to the connected LEDs.
If the channel mapping has 3 colors, you need to give the data in the sequence RGBRGBRGB… if the channel mapping has 4 colors you need to give data in the sequence RGBWRGBWRGBW…
The data is double buffered and the colors will be transfered to the LEDs when the next frame duration ends (see BrickletLEDStripV2#set_frame_duration).
Generic approach:
-
Set the frame duration to a value that represents the number of frames per second you want to achieve.
-
Set all of the LED colors for one frame.
-
Wait for the CALLBACK_FRAME_STARTED callback.
-
Set all of the LED colors for next frame.
-
Wait for the CALLBACK_FRAME_STARTED callback.
-
And so on.
This approach ensures that you can change the LED colors with a fixed frame rate.
169 170 171 172 173 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 169 def set_led_values_low_level(index, value_length, value_chunk_offset, value_chunk_data) check_validity send_request FUNCTION_SET_LED_VALUES_LOW_LEVEL, [index, value_length, value_chunk_offset, value_chunk_data], 'S S S C58', 8, '' end |
#set_status_led_config(config) ⇒ Object
Sets the status LED configuration. By default the LED shows communication traffic between Brick and Bricklet, it flickers once for every 10 received data packets.
You can also turn the LED permanently on/off or show a heartbeat.
If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
378 379 380 381 382 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 378 def set_status_led_config(config) check_validity send_request FUNCTION_SET_STATUS_LED_CONFIG, [config], 'C', 8, '' end |
#set_write_firmware_pointer(pointer) ⇒ Object
Sets the firmware pointer for BrickletLEDStripV2#write_firmware. The pointer has to be increased by chunks of size 64. The data is written to flash every 4 chunks (which equals to one page of size 256).
This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.
351 352 353 354 355 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 351 def set_write_firmware_pointer(pointer) check_validity send_request FUNCTION_SET_WRITE_FIRMWARE_POINTER, [pointer], 'L', 8, '' end |
#write_firmware(data) ⇒ Object
Writes 64 Bytes of firmware at the position as written by BrickletLEDStripV2#set_write_firmware_pointer before. The firmware is written to flash every 4 chunks.
You can only write firmware in bootloader mode.
This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.
365 366 367 368 369 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 365 def write_firmware(data) check_validity send_request FUNCTION_WRITE_FIRMWARE, [data], 'C64', 9, 'C' end |
#write_uid(uid) ⇒ Object
Writes a new UID into flash. If you want to set a new UID you have to decode the Base58 encoded UID string into an integer first.
We recommend that you use Brick Viewer to change the UID.
420 421 422 423 424 |
# File 'lib/tinkerforge/bricklet_led_strip_v2.rb', line 420 def write_uid(uid) check_validity send_request FUNCTION_WRITE_UID, [uid], 'L', 8, '' end |