I started off sampling the entire screen and maping it into pixels in a webview.
And then I decided instead to only sample pixels around the border of the screen and then map those into an led strip! (but the led updates were slow b/c I was sending the data to the Arduino in a dumb way and updating the led strip had an annoying slow-updating raster-effect)
SO THEN! I decided to improve the I/O and add a slow color transition effect to really set the mood XD. Check out the YouTube video below:
and now I'm probably done writing c code for another decade :-P
- An electron app uses
robotjs
to scan some set of sample coordinates randomly in a loop visiting each sample-coord exactly once. In this case the sample coordinates are 80 pixels around the right, top and left border of the screen. - The electron app uses
serial.js
to send the color data along a usb port to an Arduino. The color data is 8-bytes encoded as such,[rgbi]
, where i is the index of a light on the led strip and rgb are the hex color values. Each value is encoded as a hex string. So all purple (max r and b) at pixel 5 looks like"FF00FF05"
. - The Arduino runs a loop that first looks for data on the serial buffer. It will split the message and pipe that data into
uint32_t[]
calledstripBuffer
. So that has to decode the hex colors into auint32_t
. - When there is no message available, it will then compare each index of
stripBuffer
to anotheruint32_t
array calledstripMemory
. - If the color value at the index differs (between the buffer and the memory of the led strip) it will adjust
stipMemory
for each rbg value by the(difference / 10) || 1
(this is the fade transition), then will update the actual led strip with the value instripMemory
! :D