<rdf:RDF
    xmlns:s='http://snipsnap.org/rdf/snip-schema#'
    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
    xml:base='http://www.loadbang.net/rdf'>
    <s:Snip rdf:about='http://www.loadbang.net/rdf#Software/net.loadbang.shado/Tutorials/Buttons'
         s:cUser='nick'
         s:oUser='nick'
         s:mUser='nick'>
        <s:name>Software/net.loadbang.shado/Tutorials/Buttons</s:name>
        <s:content>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~~:&#xD;&#xA;&#xD;&#xA;{code:python}&#xD;&#xA;def press(x, y, how):&#xD;&#xA;    &apos;A button has been pressed: print out the values.&apos;&#xD;&#xA;    print &quot;X=%d, Y=%d, how=%d&quot; % (x, y, how)&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;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.&#xD;&#xA;&#xD;&#xA;This function has a documentation string, and a single line of code:&#xD;&#xA;&#xD;&#xA;{code:python}&#xD;&#xA;print &quot;X=%d, Y=%d, how=%d&quot; % (x, y, how)&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;This prints the values as a formatted line of text. (For all the gory details, see {link:here|http://docs.python.org/library/stdtypes.html#string-formatting}, but in summary, we are printing out a string with each &quot;%d&quot; replaced with a number.)&#xD;&#xA;&#xD;&#xA;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).&#xD;&#xA;&#xD;&#xA;You should see output looking rather like this:&#xD;&#xA;&#xD;&#xA;{code:none}&#xD;&#xA;X=0, Y=0, how=1&#xD;&#xA;X=0, Y=0, how=0&#xD;&#xA;X=2, Y=1, how=1&#xD;&#xA;...&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;We aren&apos;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.&#xD;&#xA;&#xD;&#xA;Coordinates: (0, 0) (left illustration), (7, 7) (right).&#xD;&#xA;&#xD;&#xA;{image:img=m1.png}&#xD;&#xA;&#xD;&#xA;1 Full Script&#xD;&#xA;&#xD;&#xA;{code:python}&#xD;&#xA;&apos;&apos;&apos;&#xD;&#xA;A script which prints out button presses to the Max window.&#xD;&#xA;&apos;&apos;&apos;&#xD;&#xA;&#xD;&#xA;def press(x, y, how):&#xD;&#xA;    &apos;A button has been pressed: print out the values.&apos;&#xD;&#xA;    print &quot;X=%d, Y=%d, how=%d&quot; % (x, y, how)&#xD;&#xA;{code}&#xD;&#xA;</s:content>
        <s:mTime>2009-03-01 20:02:11.651</s:mTime>
        <s:cTime>2009-03-01 19:33:15.373</s:cTime>
        <s:comments
             rdf:type='http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag'/>
        <s:snipLinks>
            <rdf:Bag>
                <rdf:li rdf:resource='http://www.loadbang.net/rdf#Software/net.loadbang.shado/Tutorials'/>
                <rdf:li rdf:resource='http://www.loadbang.net/rdf#Software/net.loadbang.shado/Tutorials/First Light'/>
                <rdf:li rdf:resource='#snipsnap-index'/>
                <rdf:li rdf:resource='http://www.loadbang.net/rdf#'/>
                <rdf:li rdf:resource='http://www.loadbang.net/rdf#Software/net.loadbang.shado'/>
                <rdf:li rdf:resource='http://www.loadbang.net/rdf#Software/net.loadbang.jython'/>
                <rdf:li rdf:resource='http://www.loadbang.net/rdf#Software/net.loadbang.shado/Workbench'/>
                <rdf:li rdf:resource='http://www.loadbang.net/rdf#SnipSnap/config'/>
                <rdf:li rdf:resource='#snipsnap-search'/>
                <rdf:li rdf:resource='http://www.loadbang.net/rdf#Software/net.loadbang.shado/Tutorials/Hello World'/>
                <rdf:li rdf:resource='http://www.loadbang.net/rdf#Software/net.loadbang-SQL'/>
                <rdf:li rdf:resource='http://www.loadbang.net/rdf#Software/net.loadbang.shado/Tutorials/Installation'/>
                <rdf:li rdf:resource='http://www.loadbang.net/rdf#Software/net.loadbang.web'/>
                <rdf:li rdf:resource='http://www.loadbang.net/rdf#Software/TextBrick'/>
                <rdf:li rdf:resource='#snipsnap-portlet-1'/>
                <rdf:li rdf:resource='http://www.loadbang.net/rdf#Software/Nixies'/>
                <rdf:li rdf:resource='http://www.loadbang.net/rdf#Software/net.loadbang.shado/README'/>
                <rdf:li rdf:resource='http://www.loadbang.net/rdf#Software/net.loadbang-lib'/>
                <rdf:li rdf:resource='http://www.loadbang.net/rdf#Software/net.loadbang.shado/Tutorials/The Demos'/>
                <rdf:li rdf:resource='http://www.loadbang.net/rdf#Software/net.loadbang.shado/Tutorials/'/>
                <rdf:li rdf:resource='http://www.loadbang.net/rdf#Software/Registry'/>
                <rdf:li rdf:resource='http://www.loadbang.net/rdf#Software/textbrick'/>
                <rdf:li rdf:resource='#nick'/>
            </rdf:Bag>
        </s:snipLinks>
        <s:attachments>
            <rdf:Bag>
                <rdf:li>
                    <s:Attachment rdf:about='http://www.loadbang.net/space/Software/net.loadbang.shado/Tutorials/Buttons/m1.png'
                         s:fileName='m1.png'
                         s:contentType='image/png'
                         s:size='4254'>
                        <s:date>Sun Mar 01 20:00:35 UTC 2009</s:date>
                    </s:Attachment>
                </rdf:li>
            </rdf:Bag>
        </s:attachments>
    </s:Snip>
</rdf:RDF>
