In this lesson, we use a potentiometer to control the brightness of the LED module.
After creating a new project, click on the Simulation icon on the left side of the page to enter the Simulation page.
Connect the Potentiometer to A0 and LED module to P0 of the Ezblock Pi. Then connect the VCC and GND to 3.3V and GND respectively. The brightness of LED will change with the variable read values of potentiometer.
Click the Create variable button in the Variables category to create a variable called potVal.
Read the value of the potentiometer to assign to the variable potVal.
In the Sensor Kit category, drag an LED module block below the set potVal to block.
Since the read value of potentiometer ranges 0-4095 and the value of the brightness ranges 0-100, a map block is needed to map 0-4095 to 0-100. Get a map block to put it into LED module block.
Modify the values as shown below. In addition, potVal block comes from the Variables category. Add a delay block below the LED module block.
Go to the Simulation page and click on the Run button, then drag the slider to simulate the value of potentiometer sensor, when the value read is greater than 1500, the LED light up; otherwise, it will turn off. Now click Flash to download the code.