Aaaf5050McK12LED

class quanser.devices.interfaces.Aaaf5050McK12LED

A Python wrapper for the Quanser Devices API interface to the AAAF5050_MC_K12 LED strip on QCar 2.

Example

>>> from quanser.devices import Aaaf5050McK12LED
>>> leds = Aaaf5050McK12LED()
close()

Close the LED strip.

Example

>>> from quanser.devices import Aaaf5050McK12LED
>>> leds = Aaaf5050McK12LED()
>>> leds.open("spi://localhost:1?memsize=420,word=8,baud=3333333,lsb=off,frame=1", 33)
>>> ...
...
>>> leds.close()
open(uri, max_leds)

Opens the AAAF5050_MC_K12 LED strip.

Parameters
  • uri (string) – A URI used for communicating with the device. Numerous URI parameters are available. For the Quanser QCar 2, a suitable URI is “spi://localhost:1?memsize=420,word=8,baud=3333333,lsb=off,frame=1”.

  • max_leds (int) – The maximum number of LEDs in the LED strip. For the Quanser QCar 2, this number should be 33.

Example

>>> from quanser.devices import Aaaf5050McK12LED
>>> leds = Aaaf5050McK12LED()
>>> leds.open("spi://localhost:1?memsize=420,word=8,baud=3333333,lsb=off,frame=1", 33)
>>> ...
...
>>> leds.close()
writeColors(led_colors, num_leds)

Write colors to the LED strip.

Parameters
  • led_colors (array_like) – An Nx3 array of unsigned 8-bit integers containing the colors for each LED in the strip. The three color components are red, green, and blue in that order and each component ranges from 0 to 255. Alternatively, it may be an Nx3 list of lists, or list of (R, G, B) tuples or simply a single (R, G, B) tuple or [R, G, B] list or array.

  • num_leds (int) – The number of LED colors from the led_colors argument to write to the LED strip. If this number exceeds the number of colors in the led_colors argument then the last element is used for the remaining LEDs.

Example

Make all the LEDs red.

>>> from quanser.devices import Aaaf5050McK12LED
>>> leds = Aaaf5050McK12LED()
>>> num_leds = 33
>>> leds.open("spi://localhost:1?memsize=420,word=8,baud=3333333,lsb=off,frame=1", num_leds)
>>> leds.writeColors((255, 0, 0), num_leds)
...
>>> leds.close()

Make the first three LEDs red, green and blue and the rest magenta using a list of tuples.

>>> from quanser.devices import Aaaf5050McK12LED
>>> leds = Aaaf5050McK12LED()
>>> num_leds = 33
>>> leds.open("spi://localhost:1?memsize=420,word=8,baud=3333333,lsb=off,frame=1", num_leds)
>>> leds.writeColors([(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 0, 255)], num_leds)
...
>>> leds.close()

Make the first three LEDs red, green and blue and the rest magenta using a list of lists.

>>> from quanser.devices import Aaaf5050McK12LED
>>> leds = Aaaf5050McK12LED()
>>> num_leds = 33
>>> leds.open("spi://localhost:1?memsize=420,word=8,baud=3333333,lsb=off,frame=1", num_leds)
>>> leds.writeColors([[255, 0, 0], [0, 255, 0], [0, 0, 255], [255, 0, 255]], num_leds)
...
>>> leds.close()

Make the first LED red and the rest green using a list of arrays.

>>> import array as arr
>>> from quanser.devices import Aaaf5050McK12LED
>>> leds = Aaaf5050McK12LED()
>>> num_leds = 33
>>> leds.open("spi://localhost:1?memsize=420,word=8,baud=3333333,lsb=off,frame=1", num_leds)
>>> red = arr.array("B", [255, 0, 0]])
>>> green = arr.array("B", [0, 255, 0]])
>>> colors = [red, green]
>>> leds.writeColors(colors, num_leds)
...
>>> leds.close()

Make the first three LEDs red, green and blue and the rest light magenta using floating-point.

>>> import numpy as np
>>> from quanser.devices import Aaaf5050McK12LED
>>> leds = Aaaf5050McK12LED()
>>> num_leds = 33
>>> leds.open("spi://localhost:1?memsize=420,word=8,baud=3333333,lsb=off,frame=1", num_leds)
>>> leds.writeColors([(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0), (0.5, 0.0, 0.5)], num_leds)
...
>>> leds.close()

Clear all the LEDs.

>>> import numpy as np
>>> from quanser.devices import Aaaf5050McK12LED
>>> leds = Aaaf5050McK12LED()
>>> num_leds = 33
>>> leds.open("spi://localhost:1?memsize=420,word=8,baud=3333333,lsb=off,frame=1", num_leds)
>>> leds.writeColors([], num_leds)
...
>>> leds.close()