Let's start by adding a variable where you can store data. Name the variable as ``light`` and ``||variables:set||`` the value of the variable to the ``||input:light level||`` block from the ``||input:Input||`` drawer. This will get the light level as some value between `0` (dark) and `255` (bright). The light is measured by using various LEDs from the screen. Your code will look like this:
We also want to play music when the **A** button is pressed. To do that, register an event handler that will execute whenever you click on the **A** button. Open the ``||input:Input||`` drawer and get out an ``||input:on button A pressed||`` block. Next, add a ``||music:rest||`` to play nothing for `1/16` of a beat. Pull the ``||variables:set light||`` block in there too. Your code should look like this:
Click on the ``||logic:Logic||`` drawer and find an ``||logic:if||`` block to use so that some of your code will run conditionally depending on whether a [Boolean](/types/boolean) condition is either `true` or `false`. Go get the ``||logic:0 <0||``comparisonblockanputitinastheconditionforthe``||logic:if||``.Theninsertthevariable``||variables:light||``intothepartoftheinequalitywherethefirst`0`is.You'llfindthevariable``||variables:light||``inthe``||variables:Variables||``drawer.Finally,insert`25`inthesecondpartofthecomparisoninsteadof`0`.Modifyyourcodesothatitchecksthelightlevellikethis:
* If ``||logic:light <25||``,play``||music:ringtone||``for``MiddleC``
* If this condition is not `true`, play ``||music:ring tone||`` for ``Middle A``
Now, we want to add more conditional statements by clicking on the **(+)** at the bottom of the `if`. Add **5** ``||logic:else if||`` and **1** final ``||logic:else||`` inside the ``||logic:if||`` block structure. Set the comparison blocks inside the new conditionals as:
* If ``||logic:light <50||``,play``||music:ringtone||````MiddleD``
* If ``||logic:light <100||``,play``||music:ringtone||````MiddleE``
* If ``||logic:light <150||``,play``||music:ringtone||````MiddleF``
* If ``||logic:light <180||``,play``||music:ringtone||````MiddleG``
* If these conditions are not true, play ``||music:ring tone||`` ``Middle A``