Set individual pixels on LED matrix
mb720 opened this issue · 4 comments
Hi and thanks a lot for inputmodule-rs!
In case I haven't missed anything, there's no way with inputmodule-control to set individual pixels on the LED matrix.
Optimally, users could pass a list of 9x34 brightness values to inputmodule-control which set each LED to the respective brightness.
I've been playing with it today. The Python library can be imported and can send a matrix. Though, the library as is will use max brightness if sending a full array. I used some of the library code to send the matrix to the device one column at a time to support brighness.
You can see my fairly simple code here: https://github.com/TomFaulkner/fw-led
Optimally, users could pass a list of 9x34 brightness values to inputmodule-control which set each LED to the respective brightness.
How would you like to specify the pixels?
The code does indeed support setting individual pixels, but what do you think is the most generic way to tell it which pixels to activate?
You can try led-matrix --image-gray res/greyscale.gif or led-matrix led-matrix --image-bw stripe.png.
Both of those read from a 9x34 pixel image and draw exactly those pixels, either greyscale or black/white.
If you want direct code access you can refer to render_matrix in inputmodule-control/src/inputmodule.rs.
Thanks for the pointer!
I'm working on a prototype script that sets the LEDs to a brightness value defined in a matrix provided as a string on the commandline. I'll probably get around finishing it and attaching it here this week.
Here's the repo with the experimental code.
You can specify a brightness matrix on the command line, for example:
./led_prototype.py --device /dev/ttyACM0 --brightness-matrix '[0,1,2,3,4,5,6,7,8],[9,10,11,12,13,14,15,16,17],[18,19,20,21,22,23,24,25,26],[27,28,29,30,31,32,33,34,35],[36,37,38,39,40,41,42,43,44],[45,46,47,48,49,50,51,52,53],[54,55,56,57,58,59,60,61,62],[63,64,65,66,67,68,69,70,71],[72,73,74,75,76,77,78,79,80],[81,82,83,84,85,86,87,88,89],[90,91,92,93,94,95,96,97,98],[99,100,101,102,103,104,105,106,107],[108,109,110,111,112,113,114,115,116],[117,118,119,120,121,122,123,124,125],[126,127,128,129,130,131,132,133,134],[135,136,137,138,139,140,141,142,143],[144,145,146,147,148,149,150,151,152],[153,154,155,156,157,158,159,160,161],[162,163,164,165,166,167,168,169,170],[171,172,173,174,175,176,177,178,179],[180,181,182,183,184,185,186,187,188],[189,190,191,192,193,194,195,196,197],[198,199,200,201,202,203,204,205,206],[207,208,209,210,211,212,213,214,215],[216,217,218,219,220,221,222,223,224],[225,226,227,228,229,230,231,232,233],[234,235,236,237,238,239,240,241,242],[243,244,245,246,247,248,249,250,251],[252,253,254,255,0,1,2,3,4],[5,6,7,8,9,10,11,12,13],[14,15,16,17,18,19,20,21,22],[23,24,25,26,27,28,29,30,31],[32,33,34,35,36,37,38,39,40],[41,42,43,44,45,46,47,48,49]'
The value of --brightness-matrix specifies the matrix in a format that I personally find intuitive and also generic.
The code for led_prototype.py is here:
matrix_from_stringconverts the matrix string from the command line into a two-dimensional Python list (matrix). To go the other way around, from a Python matrix to a string in that format, usematrix_to_string.draw_brightness_matrixdraws that Python matrix.- As a side note, I've also experimented with turning LEDs on and off (no variations in brightness) based on a matrix in
black_white_draw_test. That function also documents why we need 39 bytes to turn the 34*9 LEDs on and off.