Retro Gadgets: Controlling A LED Strip With A Button

Retro Gadgets is an upcoming game in which players have a freedom to create and build their own electrifying gadgets from scratch. You can invent and build any type of gadget, and then use coding to make it work like it’s real. One of the cool features that you can do is install a LED strip which will give you a better light and ambient, but somehow you will have to control it with a button.

In this guide, you can learn Controlling a LED Strip with a Button in Retro Gadget!

Controlling A LED Strip With A Button – Retro Gadgets

In Retro Gadget, you will be able to find tons of gadgets that are already built by the community, but also you can build a completely new one and make it even better than the others.

There are plenty of cool features that can be installed and used on any gadget, but the point is to make it work.

If you installed any type of light or LED Strip, in order to turn it on or off, you will need to install a button that will have that function.

Once you have your imaginary gadget done on a board, you need to place a couple of LEDs from the output menu items.

After the LEDs are installed, you will need a button from the input menu. The button can be placed anywhere on your gadget.

Before it works, you must install the CPU on the back of the board which is needed to code the gadget.

The CPU can be found in the misc menu. Even the smallest CPU will make it work without any interruptions.

Now, once you are done until here, next is to open your drawer on the left side of the screen where you can check your gadget, and then go into Assets.

You will have to select an asset in the left column which in our example is the “CPU0.lua” that is placed on the gadget already.

Select the CPU and press the Edit button. It will open another window where you can start coding.

If you type “gdt.” you will see all the components that are installed on your device. Working on the LEDs, you will need to select the Led components which are Led0, Led1, and LedStrip0.

Now, go straight into the update function which is executed every single time tick, and write down the following code:

      gdt.Led0.State = gdt.LedButton0.ButtonState

      gdt.Led1.State = gdt.LedButton0.ButtonState


This will make your button control the both single LEDs to turn them on/off.

If you want the LED strip to work also, which is made of 8 LED lights in total, you need to use a bit different code.

gdt.Led0.State = gdt.LedButton0.ButtonState

gdt.Led1.State = gdt.LedButton0.ButtonState

for    ledCount=1,8 do

          gtd.LedStrip0.States[ledCount] = gtd.LedButtin0.ButtonState


With this code above, you will be able to control the LED strip together with the single LEDs when turning on/off.

Another interesting feature of controlling the LED strip is to control the colors of each LED.

In the software menu, you can easily change the States and Colors of each of the LEDs on the strip. You can choose which LED to turn on/ff separately, and what color it will light when you press the button.