In this lesson, we will control the LED light on and off with a button.
After creating a new project, click on the Simulation icon on the left to enter the Simulation page.
Connect the LED module to D1 and connect the button module to D0 of Ezblock Pi. Then connect the VCC and GND to 3.3V and GND respectively. When the button is pressed, a low level signal 0 will be output, and then D1 is set to 1 to illuminate LED.
Place an if do block that is under the Logic category into the Forever block to judge if the LED module needs to be lit.
Then place a Comparison Operator ( = ) block behind the if block to create a judgment condition.
Drag a Button block from Sensor Kit category into the first slot, and 0 block from the math category to the second slot. When the button is pressed, the value of the button read is equal to 0.
Lights up the LED module if the button is pressed.
Add a delay block to keep the LED on for 200ms after the button is pressed.
Click the Settings icon in the top left corner of the if do block, place an else block below the if block, and you will see that the if do block becomes if do else block.
If the button is pressed, lit the LED. otherwise, turn it off.
Go to the Simulation page and click on the Run button. If the button is pressed, the light turns on; otherwise, it turns off, indicating that there is no problem with the code. Now, save your project, connect the Bluetooth and click Flash to download the code.