Skip to content

05 Examples

Alvaro edited this page Feb 23, 2019 · 5 revisions

back In the sw section you will find some examples. They will allow you to discover the functionalities of the device and explore its capabilities.

Exercise 1

Understand how to address and program the RGB LEDs. For changing the value just modify the array ledPad, where the first index is the LEd (from 0 to 15) and the second if the color (0 for red, 1 for green, 2 for blue). This example will light up the first LED (index 0) with a green color. Note that each color intensity goes from 0 to 255.

ledPad[0][0] = 0;    //0 corresponds to the intensity of red color
ledPad[0][1] = 255;  //1 corresponds to the intensity of green color
ledPad[0][2] = 0;    //2 corresponds to the intensity of blue color

Exercise 2

Create a simple animation using the delay() function. Also understand how a for structure works. The most important part of the code is this section:

for (int i = 0; i < 16; i++) {
  ledPad[i][0] = 0;
  ledPad[i][1] = 255;
  ledPad[i][2] = 0;
  delay(500);
  updateLEDs();
}

This code will light up in green colors all the LEDs, from fist 0 to last 15.

Exercise 3

Understand the function digitalRead and if-elsestructure. Note that will pinMode(SW_0_PIN, INPUT) a pin is set as input and with uint8_t switch0 = digitalRead(SW_0_PIN) the state is read. And with an if-else you can control wether to enter in a code section or not.

if (switch0 == 1 ){
  Serial.println("Button 0 is pushed");  
}

Exercise 4

In this exercise we will start to use the MIDI protocol to send some simple messages. The most important part is:

  noteOn(0, 48, 127);
  MidiUSB.flush();
  delay(500);

Where the fist value 0 mean the MIDI channel, the second means the note and the third the intensity. Note that 48 corresponds to a C2. If you have in your computer a DAW or a program that receives MIDI you will be able to get the noteOn message.

Exercise 5

This last exercise is quite similar to this code. You can run in your computer a program like Logic or Ableton to start playing some music. Feel free to modify the following section.

// RGB LED color Definition                                             //
#define OFF_R  50  // OFF PAD Color Red    [0:255]                      //
#define OFF_G  50  // OFF PAD Color Green  [0:255]                      //
#define OFF_B  50  // OFF PAD Color Blue   [0:255]                      //
                                                                        //
#define ON_R   0   // ON PAD Color Red     [0:255]                      //
#define ON_G   0   // ON PAD Color Green   [0:255]                      //
#define ON_B   255 // ON PAD Color Blue    [0:255]                      //
                                                                        //
// MIDI notes definition                                                //
uint8_t notes[4][4] = {                                                 //
{32,33,34,35},                                                          //
{36,37,38,39},                                                          //
{40,41,42,43},                                                          //
{44,45,46,47},                                                          //
};                                                                      //
uint8_t velocity[4][4] = {                                              //
{127,127,127,127},                                                      //
{127,127,127,127},                                                      //
{127,127,127,127},                                                      //
{127,127,127,127},                                                      //
};                                                                      //
// ---------------------------------------------------------------------//

In this section you can set the colors that the LEDs will have when you are not pushing them. Use the variables OFF_R, OFF_G, OFF_B for that. Only values from 0 to 255 are allowed.

You can also configure the color that each button will have when you push them. Configure it in ON_R, ON_G, ON_B.

In notes and velocityyou can also configure each note and each velocity for each PAD.

Clone this wiki locally