# How can I find adjacent controllers (FW2 / FW3 question)

**URL:** <https://forum.electra.one/t/how-can-i-find-adjacent-controllers-fw2-fw3-question/1793>\
**Category:** Developers\
**Tags:** lua\
**Created:** [December 17, 2022, 2:59pm UTC](https://forum.electra.one/t/how-can-i-find-adjacent-controllers-fw2-fw3-question/1793 "2022-12-17T14:59:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![NewIgnis](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/newignis/32/767_2.png) [@NewIgnis](https://forum.electra.one/u/NewIgnis)\
**Post date:** [December 17, 2022, 2:59pm UTC](https://forum.electra.one/t/how-can-i-find-adjacent-controllers-fw2-fw3-question/1793/1 "2022-12-17T14:59:59Z")

</div>

Here’s what I want to do in all my Mod Matrices:

- when depth of a modulation = 0, then all of its controls should be RED (or grey in FW3)
- when depth of a modulation \<\> 0, then all of its controls should be GREEN

I try to solve this by giving a function colorDepth to the depth controls, but how do I then in the lua function:

- retrieve the actual control belonging to that depth ?
- retrieve the actual position (slot) of the control in FW2, or control ID in FW3?
- find the 3 three adjacent controls?
  - in FW2 , these are the ones occupying the slots - 6, -5 and + 1 compared to the one of Depth
  - in FW3, these are the ones with an ID - 2, -1 and + 1 compared to the one of Depth

---

<div class="post-metadata">

**Author:** ![oldgearguy](https://avatars.discourse-cdn.com/v4/letter/o/f4b2a3/32.png) [@oldgearguy](https://forum.electra.one/u/oldgearguy)\
**Post date:** [December 17, 2022, 5:30pm UTC](https://forum.electra.one/t/how-can-i-find-adjacent-controllers-fw2-fw3-question/1793/2 "2022-12-17T17:30:10Z")

</div>

I’m doing this for a configuration screen (and some other stuff).

I just pulled up my most recent preset, but it looks like my last changes were not saved.

Basic idea (I’ll paste pic, code a bit later) is to define the consecutive controls and then either use

```auto
   local message = ValueObject:getMessage()
   local paramNum = message:getParameterNumber()
   -- 53 is the magic number of the first param in the list - 1 just to make array indexing easier
   local ccToSend = ccMap[paramNum - 53]

```

or

```auto
   local message = ValueObject:control()
   local paramNum = control:getId()
   -- 121 is the first ID of the controls -1 just to make indexing into arrays easier
   local ccToSend = ccMap[paramNum - 121]

```

---

<div class="post-metadata">

**Author:** ![oldgearguy](https://avatars.discourse-cdn.com/v4/letter/o/f4b2a3/32.png) [@oldgearguy](https://forum.electra.one/u/oldgearguy)\
**Post date:** [December 17, 2022, 5:48pm UTC](https://forum.electra.one/t/how-can-i-find-adjacent-controllers-fw2-fw3-question/1793/3 "2022-12-17T17:48:03Z")

</div>

attached is a zip file with a couple screen shots and a text file with the code that implements it  
Hope some of it helps

you’ll also need this array (forgot to copy/paste it)

trkCCName = {“Volume”, “Feedback”, “Pan”, “Speed”}

[cc\_config.zip](https://forum.electra.one/uploads/short-url/lFR4vKYdaraFbnsKBZs21GneQUS.zip) (33.5 KB)

---

<div class="post-metadata">

**Author:** ![NewIgnis](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/newignis/32/767_2.png) [@NewIgnis](https://forum.electra.one/u/NewIgnis)\
**Post date:** [December 17, 2022, 7:27pm UTC](https://forum.electra.one/t/how-can-i-find-adjacent-controllers-fw2-fw3-question/1793/4 "2022-12-17T19:27:26Z")

</div>

congrats by the way on being 2 years on the forum !

---

<div class="post-metadata">

**Author:** ![oldgearguy](https://avatars.discourse-cdn.com/v4/letter/o/f4b2a3/32.png) [@oldgearguy](https://forum.electra.one/u/oldgearguy)\
**Post date:** [December 17, 2022, 7:55pm UTC](https://forum.electra.one/t/how-can-i-find-adjacent-controllers-fw2-fw3-question/1793/5 "2022-12-17T19:55:04Z")

</div>

Seems like just yesterday asking my first questions.
