This is a simple script which reports button presses on the monome. We print the button positions to the Max window. To do this we need a function with the particular name
press:
def press(x, y, how):
'A button has been pressed: print out the values.'
print "X=%d, Y=%d, how=%d" % (x, y, how)Whenever a button is pressed or released, the workbench attempts to call a function called
press with three argument values: the X and Y position of the press, and a value to distinguish between a button press and a release. The
how value will be
1 for press,
0 for release.
This function has a documentation string, and a single line of code:
print "X=%d, Y=%d, how=%d" % (x, y, how)
This prints the values as a formatted line of text. (For all the gory details, see
here, but in summary, we are printing out a string with each "%d" replaced with a number.)
The entire script is below. Once it is running, you will notice that the coordinate system of the monome runs from a top-left point of (0, 0). In our eight-by-eight examples the bottom-right is at (7, 7). This script will actually work for a monome of any size: on a two fifty six, the bottom-right button is at (15, 15).
You should see output looking rather like this:
X=0, Y=0, how=1
X=0, Y=0, how=0
X=2, Y=1, how=1
...
We aren't doing anything with the LEDs yet, so no lights will come on. Unlike on many other devices, there is no hardware link between buttons and lights: soon we will start using
shado to provide this linkage in software.
Coordinates: (0, 0) (left illustration), (7, 7) (right).
Full Script
'''
A script which prints out button presses to the Max window.
'''def press(x, y, how):
'A button has been pressed: print out the values.'
print "X=%d, Y=%d, how=%d" % (x, y, how)