Official website of the SkyMonome library
Return to the index

Note that you must have a program that don't close immediately. The good manner is to open a frame on the screen in parallel of Monome construction.
Beginning with SkyMonome
Firstly, you have to create a Monome object :
Monome monome=new Monome("My Monome",Monome.MonomeSize.MONOME_64,"localhost","/40h",8000,8080);
Hier, we suppose that MonomeSerial runs on localhost and is configured with standard communication ports. The prefix is /40h, but you can change it. The monome object is an empty container, so you need to add content into it. By example, you can create a led/button couple, and add it to the monome :
LedButtonCouple ledButtonCouple=new LedButtonCouple("My first led",monome,0,0);
monome.addComponent(ledButtonCouple);
With 0,0 coordinates, the led/button couple will be located at the upper left corner. 0,0 stands for Row 0 and Column 0. By default, a led lights on when you push the button, and lights off when you release the button. This behavior corresponds to the sky.monome.behavior.LightOnPush class. You can specify a different type of behavior at the creation of the led/button couple :
LedButtonCouple ledButtonCouple=new LedButtonCouple("My first led",monome,0,0,new Toggle());
With a sky.monome.behavior.Toggle behavior, the led becomes bistable instead of monostable.

At any moment, and particulary when you have done your Monome tree, you can refresh it :
monome.refresh();
Giving actions to buttons
Here, we will give actions to our led/button couple. We will use a sky.monome.event.button.ButtonListener :
ledButtonCouple.addButtonListener(new ButtonListener<LedButtonCouple>()
{
    public void buttonActionned(ButtonEvent<LedButtonCouple> buttonEvent)
    {
        LedButtonCouple ledButtonCouple=buttonEvent.getSource2();
        System.out.println(ledButtonCouple.getName()+" is pushed or released");
    }
}
);
Each time a button action (press or release) happen, the buttonActionned(ButtonEvent) method is called. With the buttonEvent object, you will find informations about the button event. ButtonListener is an interface and in this example we have implemented it "inline".
Radios
There's a useful behavior called radio. With radios, you can create mutual selections/unselections of buttons. Push one button in the group, and all others will be cleared. How to use it :
Radio.RadioGroup radioGroup=new Radio.RadioGroup();

LedButtonCouple ledButtonCouple1=new LedButtonCouple("First button",monome,0,0,new Radio(radioGroup));
LedButtonCouple ledButtonCouple2=new LedButtonCouple("Second button",monome,1,0,new Radio(radioGroup));
LedButtonCouple ledButtonCouple3=new LedButtonCouple("Third button",monome,2,0,new Radio(radioGroup));

monome.addComponent(ledButtonCouple1);
monome.addComponent(ledButtonCouple2);
monome.addComponent(ledButtonCouple3);
Radio groups can be listened for button actions like buttons themselves (since LedButtonCouple and RadioGroup both implement the sky.monome.event.button.ButtonManager interface) :
radioGroup.addButtonListener(new ButtonListener<Radio.RadioGroup>()
{
    public void buttonActionned(ButtonEvent<Radio.RadioGroup> buttonEvent)
    {
        if(buttonEvent.getButtonAction()==ButtonEvent.ButtonAction.BUTTON_PUSHED)
        {
            Radio.RadioGroup radioGroup=buttonEvent.getSource2();
            System.out.println(radioGroup.getActiveRadio().
                                                                                    getLedButtonCouple().getName()+" is pushed in the group");
        }
    }
}
);
Analogs
If you have soldered knobs, accelerometer, or any other external sensor on the Monome board, you can use them with the class sky.monome.Analog. At construction of Analog objects, you need to give physical rank of your analog on the board (eventually offsetted by MonomeSerial) :
Analog analog=new Analog("My knob",monome,0);
monome.addComponent(analog);
In the same manner, analogs can trigger listeners :
analog.addAnalogListener(new AnalogListener()
{
    public void analogMoved(AnalogEvent analogEvent)
    {
        System.out.println("The new value is "+analogEvent.getValue());
    }
}
);
To be continued !