This fun project puts together Hexabitz IR range sensor module (H08R60) with six RGB LED modules (H01R00) to create a magic array! Using gesture control you can change colors or intensity in various modes.
Estimated hardware build time: 10 minutes
Estimated software development time: 1 hour
The IR sensor module does all the work basically. It detects motion (or measures distance) and generates a control command that is broadcasted to all LED modules. Since the sensor is in the middle of the array, the button is read by one of the LED modules and its value is sent to the sensor module by a memory write API.
I didn't define a fixed topology in this project. Instead, I ran the exploration CLI command starting from the module connected to the push button and then let the modules generate their own topology as shown below.
Attached project firmware includes two uVision projects. One for the IR sensor module (H08R6) and another for the LED modules (H01R0). Note that for LEDs, all of them except the one with the push button are using exact firmware. That's why I created only two targets in that project: Target 1 for module 1 connected to the push button and Target 2 for all other LED modules.
Here's a description for all the array modes.
First LED click turns off all LEDs. When the array powers on, the mode counter starts from zero but you can have start from 1 as well. Each button click also triggers an indicator LED blink.
This mode cycles through colors by changing distance.
This mode varies LED intensity based on distance. Note how it saves your last intensity setting so that it doesn't jump to maximum when you remove your hand.
This mode swipes right or left to turn the LEDs ON/OFF.
This mode swipes right or left to cycle through LED colors. So fun!
As mentioned before, the RGB LED code is very simple. Basically all LED modules have native module firmware except the one connected to the push button which has a simple code that defines a button with a click callback. In the callback, the code cycles through modes and writes the value to a BOS variable via a remote write API. Check this article about remote memory access in Hexabitz arrays.
The IR sensor module code is a bit more complicated but easy to understand. First, we define the BOS variable which the remote RGB LED module will write to. Then, we set sensor units to mm and stream range continuously to a memory variable at 20 Hz.
After that, we cycle through modes at 100 Hz and broadcast the appropriate message for each mode. For example, mode 1 just broadcasts a turn OFF message to all LEDs. Check this article for more details about messaging in Hexabitz.
In modes 2 and 3, we convert measured absolute range directly into color or use the range to cycle through available basic colors and then broadcast a set color message. Color mapping for absolute distance is straightforward. The
HorizontalSweepToColor() function calls another function that detects a sweep or a motion. The
HorizontalSweepToColor() then cycles through detected sweeps to change color.
Note how the broadcast message is only sent if there's a color change and not at the loop 100 Hz rate to avoid spamming the array:
Mode 5 has a lock state. If the measured range is > h08r6MaxRange, this means there's no object in the sensor field of view and the intensity shouldn't get updated. If distance to an object is > 100 mm, that distance is converted into a valid intensity value.