> For the complete documentation index, see [llms.txt](https://docs.idew.org/code-internet-of-things/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.idew.org/code-internet-of-things/tutorials/create-security-system/4.3-led-and-button-code.md).

# D-3 LED and Button Code

Next, you'll use your Smart Light device app as starter code for your Smart Security device app. The LED and button code in the two apps will be nearly identical – you'll just make a few minor changes. After that, you'll be ready to start adding new code for the motion sensor and speaker.

## Log In to Particle Build

One person on your team should log in to [Particle Build](https://login.particle.io/build) using your team's Particle account login.

Once you're logged in, you should see a new app template in the code editor.  (If not, just click the "Create New App" button in the Code menu panel.)

## Title New App

Enter `smart-security` as your app's title.

## Copy Smart Light Code

You'll use your `smart-light` app as starter code for your `smart-security` app:

1. The Code menu panel lists all your saved apps under "My apps." Click on your `smart-light` app to load its code into the code editor panel. (If the Code menu panel is **not** visible, just click the **Code** icon in the left navigation bar to show the Code menu panel.)
2. In the code editor panel, select all the existing code in your `smart-light` app, and copy it.
3. In the Code menu panel, click on your `smart-security` app listed under "My apps" to load it into the code editor panel. (If the Code menu panel is **not** visible, just click the **Code** icon in the left navigation bar to show the Code menu panel.)
4. Select all the existing code in your `smart-security` app, and then replace it by pasting in the copied code from your other app.

Save your `smart-security` app code by clicking the **Save** icon in the left navigation bar.

<div align="left"><img src="/files/-LJ0pSQvLOewPan-6Z_m" alt="Save Icon"></div>

## Modify App Code

The LED and button code in the Photon app will remain essentially the same. You'll just make some minor changes to the `lightStatus` variable and `toggleLight()` function:

1. Change the name of `lightStatus` to `deviceMode`. There should be **6** places in the code where this change needs to be made.
2. The possible values for `lightStatus` were `"off"` or `"on"`. Find the **3** places in the code where `"off"` is listed, and change each one to `"disarmed"` instead. There is **1** place in the code where `"on"` needs to be changed to `"armed"` instead.
3. Change the name of `toggleLight` to `toggleMode`. There should be **4** places in the code where this change needs to be made.
4. In the comments at the top of the code, change `Smart Light Device` to `Smart Security Device`.

These modifications do **not** change how the code functions – it just makes the code make more sense when you read it, since this app will control a Smart Security device (instead of a Smart Light).

## Flash App to Device

Be sure your Photon device is connected to Wi-Fi and Particle Cloud.

Flash your app code to your Photon device by clicking the **Flash** icon in the left navigation bar. (Particle Build will first save and verify your code before flashing it to your device.)

<div align="left"><img src="/files/-LJEjiwZZ_lGiFWTeLmW" alt="Flash Icon"></div>

Once your Photon has downloaded the new app and restarted, the updated app will start running:

* Confirm that the device still functions like the Smart Light did: the LED light should toggle between on and off each time the button is pressed. When the LED is turned on, it indicates the security system is in "armed" mode. When the LED is turned off, the security system is "disarmed."

In the next steps, you'll add code for the motion sensor and speaker to made the security system fully functional when it's "armed."


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.idew.org/code-internet-of-things/tutorials/create-security-system/4.3-led-and-button-code.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
