There are many ways to trigger events on your computer with FLORA. The following simple sketch generates configurable keyboard presses suitable for use with things like NanoStudio or Garage Band:
/*
  Piezo Keyboard glove
  
  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried & Becky Stern for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
  
*/
const int indexFinger = A9; // the piezo is connected to analog pin 9 (aka D9)
const int middleFinger = A7; // the piezo is connected to analog pin 7 (aka D6)
const int thumb = A10; // the piezo is connected to analog pin 10 (aka D10)
const int pinkyFinger = A11; // the piezo is connected to analog pin 11 (aka D12)

const int pins[] = {thumb, indexFinger, middleFinger, pinkyFinger};

char Keys[] =   {'z','x','c','v'};

boolean currentPressed[] = {false, false, false, false};

const int threshold = 40;  // threshold value to decide when the detected sound is a knock or not

void setup()
{
  //while (!Serial)
  Serial.begin(115200);
  Serial.println("start");
  Keyboard.begin();
}


void loop()                    
{ 
  for (int i=0;i<4;i++) {
    delay(1);
    long total1 = 0;
    long start = millis();
    long total =  analogRead(pins[i]);

    // check if we are sensing that a finger is touching
    // and that it wasnt already pressed
    if ((total > threshold) && (! currentPressed[i])) {
      Serial.print("Key pressed #"); Serial.print(i);
      Serial.print(" ("); Serial.print(Keys[i]); Serial.println(")");
      currentPressed[i] = true;

      Keyboard.press(Keys[i]);
    } 
    else if ((total <= threshold) && (currentPressed[i])) {
      // key was released (no touch, and it was pressed before)
      Serial.print("Key released #"); Serial.print(i);
      Serial.print(" ("); Serial.print(Keys[i]); Serial.println(")");
      currentPressed[i] = false;
      
      Keyboard.release(Keys[i]);
    }
    
    delay(5);
  }
}

Adding MIDI support to Flora


Advanced users might want to talk straight USB MIDI-- you can do that with FLORA too! You'll have to mod your Adafruit Arduino 1.0.5 installation. The following instructions are derived from PhilB's upcoming OONTZ tutorial.

To start, download and install PJRC’s Teensyduino package, an add-on for the Arduino IDE. This brings support for theirTeensy line of microcontroller boards, including excellent MIDI support. A graphical installer guides you through setup. Make sure to do the Teensification to the Adafruit Arduino IDE so you get both Flora & Teensy support

Installing George Werner’s TeeOnArdu package then lets us use the Teensy MIDI library on the FLORA. Ladyada made some changes so this package can use the stock Leonardo/Flora bootloader, saving headaches.
Installing TeeOnArdu is a little different from other software or libraries. Start by unzipping the TeeOnArdu-master.zip file that you downloaded, that much is normal. The unzipped folder that results should contain two items: a “README” file and a sub-folder called “TeeOnArdu.”

Locate your Arduino sketchbook — the folder where your own Arduino code and related files go (not the Arduino application, but the folder containing your personal work). The location is a little different for each operating system:
  • Windows: (home)\My Documents\Arduino
  • Mac: (home)/Documents/Arduino
  • Linux: (home)/sketchbook
Inside the sketchbook, create a new folder called “hardware” if one does not already exist.

Move the TeeOnArdu folder (the one alongside the README, not its parent folder) into this hardware folder.

Start the Arduino IDE. Or, if it’s already running, exit and restart it.

On the Tools→Board menu there should be a new item labeled “Flora (TeensyCore).” Select this.
There’s still a little song and dance to be done, but it’s easier than MIDI The Old Way™.

You should have previously selected Flora (TeensyCore) from the Tools→Board menu.

Now, from the Tools→USB Type menu, select Serial. Then unplug and re-plug the USB cable. This resets the FLORA bootloader, and for the next 10 seconds it appears to the system as a serial device. Quickly now…from the Tools→Serial Port menu, select the port corresponding to the Arduino board.

From the Tools→USB Type menu, now select MIDI. It’s necessary when compiling MIDI code.

Load the code below into your Arduino IDE. Before uploading the code to the board, press the mini reset button on the Flora to launch the bootloader again. There’s a 10 second window to then click Upload. If you miss it on the first try, just try again!

If you return to MIDI after working on other Arduino projects and have problems uploading code, remember to do this Serial-then-MIDI selection rigmarole. (You don’t need to do this every time you upload code, just when switching back to MIDI from a different Arduino project.)
/*
  Piezo MIDI glove
  
  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried, Phillip Burgess, & Becky Stern for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
  
*/
#define LED     7 // Pin for heartbeat LED (shows code is working)
#define CHANNEL 1  // MIDI channel number

int note;
const int indexFinger = A9; // the piezo is connected to analog pin 9 (aka D9)
const int middleFinger = A7; // the piezo is connected to analog pin 7 (aka D6)
const int thumb = A10; // the piezo is connected to analog pin 10 (aka D10)
const int pinkyFinger = A11; // the piezo is connected to analog pin 11 (aka D12)

const int pins[] = {thumb, indexFinger, middleFinger, pinkyFinger};

//char Keys[] =   {'z','x','c','v'};

boolean currentPressed[] = {false, false, false, false};

const int threshold = 40;  // threshold value to decide when the detected sound is a knock or not

void setup()
{
   pinMode(LED, OUTPUT);
  // We dont have Serial or Keyboard available in MIDI mode!!!
  //while (!Serial)
  //Serial.begin(115200);
  //Serial.println("start");
  //Keyboard.begin();
}


void loop()                    
{ 
  for (int i=0;i<4;i++) {
    delay(1);
    long total1 = 0;
    long start = millis();
    long total =  analogRead(pins[i]);

    // check if we are sensing that a finger is touching
    // and that it wasnt already pressed
    if ((total > threshold) && (! currentPressed[i])) {
      //Serial.print("Key pressed #"); Serial.print(i);
      //Serial.print(" ("); Serial.print(Keys[i]); Serial.println(")");
      currentPressed[i] = true;
      //Keyboard.press(Keys[i]);
       //note = LOWNOTE + (i & 0x0F) * 8;
      usbMIDI.sendNoteOn(60+i, 127, CHANNEL);
    } 
    else if ((total <= threshold) && (currentPressed[i])) {
      // key was released (no touch, and it was pressed before)
      //Serial.print("Key released #"); Serial.print(i);
      //Serial.print(" ("); Serial.print(Keys[i]); Serial.println(")");
      currentPressed[i] = false;
      //Keyboard.release(Keys[i]);
      usbMIDI.sendNoteOff(60+i, 0, CHANNEL);
    }
    
    delay(5);
  }
  while(usbMIDI.read()); // Discard incoming MIDI messages
}
Now you’ll need software on the computer at the other end of that cable.

This requires either a software synthesizer — a program that generates sounds using your computer’s audio hardware — or a MIDI patchbay utility, which forwards the MIDI data to a hardware synthesizer.

If you’ve done music on your computer before, you probably already have one or both of these tools. Otherwise, there are a ton of options out there, many of them free. For example, on Windows there’s the freeware Firebird2. Mac has the very basic SimpleSynth or the soup-to-nuts GarageBand. Even Linux has options. Google around for “software synthesizer”, "MIDI", “free” and “Windows”, “Mac” or “Linux” and see what you find.

There are so many options, we can’t walk you through this for every app or operating system. It’s usually pretty straightforward though, we’re confident you can find something and get it installed and running.

This guide was first published on Jun 18, 2014. It was last updated on Jun 18, 2014.

This page (Code) was last updated on Jun 18, 2014.

Text editor powered by tinymce.