PWM or Pulse Width Modulation is a technique for getting an analog output using digital signals. A digital signal, in general, can have either of the two values: HIGH/ON or LOW/OFF. If we switch the signal between these two values at an extremely fast rate, say, 500 times in 1 second, the signal at the output will appear to be continuous; it will seem as if it is an analog signal.
evive generates analog output in PWM form. It has 12 PWM pins for the same; they are numbered 2 – 13. Pin 13 is internally connected to the pin 13 LED.
set PWM pin () output as () Block
Scaling is the process of mapping a range of analog values to their corresponding digital values. The PWM output block in PictoBlox has numbers such as 0, 50, and 255 as options as output for the PWM pins. These numbers are the digital counterparts of their analog values, where 0 is 0V, and 255 is 5V.
Activity: Controlling Brightness of pin 13 LED Using PWM
- Connect evive to your computer and open PictoBlox; if already open and working on a project, save that project. Then, click on New.
- Go to the toolbar and click on the Board menu. Then select evive as your board.
- Next, click on the Connect menu and from the fly-out menu, select the Port to which evive is connected e.g. COMXX or ttyXX.Once you select the port, the icon beside the Connect tab will become connected.
- Go to the Events palette and drag and drop the when flag clicked block in the scripting area.
- Next, go to the Control palette and drag and drop the forever block below the when flag clicked block.
- Go to the evive palette and drag and drop the set pwm pin () output as () block inside the forever block; the default pin number is 13.
- Now, go to the Variables palette and create a variable named Brightness. Once you create it, you’ll also see it in the top left corner of the stage. Right click on the variable in the stage. From the drop-down menu, select slider. In doing this you’ll see a slider, i.e. a line and a small rectangle that you can slide on that line. You can control the brightness of the LED with it.
- After creating the variable, drag and drop the Brightness variable block inside the space next to the word ‘as’ in the set pwm pin () output as () block.
Below is the complete script:
Click on the green flag to run the script, and then slide the ball on the slider to change the brightness of the LED.
Click on the red octagon, next to the green flag to stop the script.
It this tutorial, you learned how to control the brightness of an LED using PWM in PictoBlox.
Hope you had fun! 🙂