From Cycling '74 Wiki
Jump to: navigation, search


Creating a Useful (Sorta...) Patch

With a few additions to our test patch, we can actually make something that shows an interesting connection between Max and the Arduino. In this case, we will use the data from the potentiometer to set the speed of a clock, and generate random output to strobe the lights. Ultra-simple, but hopefully it provides you with the means to do something more valuable for yourself.

Here's the "Final" patch of this series. I've marked the new objects in different colors:


You can download this patch from here: Media:SimpleSerialConnection-2.maxpat

The Clock

Let's first look at the blue objects. This section uses a metro object as a clock, a toggle as an on/off switch for the clock, and a scale object to handle the nasty math of the thing. The scale is most important: it takes the incoming range of values (0 through 127) and changes it to a decending - but larger - range of values (500 down to 50). We want to make it descending so that a smaller number creates a longer time between clock pulses.

If we select the proper serial port in the menu, we should be able to see the number box (labeled ms per beat) change within the range of our scale object. Depending on the size of the resistor that you have connected to the potentiometer, you may not be able to get the full range. For example, with a 330 ohm resistor, I was getting the range of 0-123 as input from the Arduino.

The Random Blinkie Lights

To get a set of blinkie lights going, we will look at the objects outlined in green. The first object is a random object with an argument of 4. Since the argument represents the range of values, and random values start with zero, it means that our output will be from 0 to 3. Next, we use a select object to determine which value (0, 1, 2 or 3) was output by random, and use that to switch the state of the toggle switches we created earlier.

If we connect the metro/clock to the random object, we will send digital pin controls that turn on and off randomly, and whose speed is controlled by the potentiometer.


Hopefully, this patch reveals how easy it is to connect your Arduino to a Max patch, and how two-way communication is an easy way to turn the focus from the computer screen to hardware. From here, you should be able to extend and enhance both the Arduino sketch as well as the Max patch to make something that is unique to your vision - and a whole lot more artistic than this!

<Previous: Create a Test Max Patch>