Controlling Pulse Width Modulation with Serial Communications

This is it. The final lesson in the final content unit of Programming Digital Media. Congratulations on getting through all of the lessons, but lets not take it easy just yet. After this we still have a few more assignments before we can be completely done with this course.

In the previous lesson we added in a way to turn an LED on and off with our P5 code. This is a wonderful tool that can allow us to have a real world response to whatever is happening on the screen. However just having the signal read as ‘on or off’ can be a little limiting. So we will be wrapping out the content in this unit by including an option for pulse width modulation control of an LED’s brightness using commands from P5. Like in the previous lessons we will be building upon the codes and circuits that we have already created.

The Circuit

For this circuit we will simply be repeating the steps taken in the previous lesson and adding a second LED circuit to another pin on the Arduino. This time is has to be one of the PWM capable pins.

The Arduino Code

The P5 Code

Bringing Everything Together


At this point we have gone through how to implement digital and analog serial communications with Arduino and P5. Before moving onto the chapter assignment, take some time to explore different combinations of components on your circuit board to see what combinations give interesting results. Also take some time to explore what kinds of triggers in P5 can be utilized in order to cause the LEDs to light up. in our examples we tied the code to a set of keystrokes and the mouse position, but how might these be applied to a sprite?