element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Blog QLab MIDI Controller - The Code
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: gadget.iom
  • Date Created: 25 Feb 2015 12:32 PM Date Created
  • Views 1148 views
  • Likes 0 likes
  • Comments 0 comments
  • qlab
  • microcontrollers
  • usb
  • midi
  • code
  • teensy
  • arduino
Related
Recommended

QLab MIDI Controller - The Code

gadget.iom
gadget.iom
25 Feb 2015

This is part III of a three part post.

Please read Part I QLab Midi Controller for an introduction to the project

and Part II QLab MIDI Controller - The Build for the build.

 

After a short delay, the current version of the MIDI Controller code is now ready.

TeensyDuino is required in order to use the Arduino IDE, the software is available from the pjrc website here: https://www.pjrc.com/teensy/td_download.html

 

/*
  QLab MIDI Controller v2.0

  Created: 10 Dec 2015 by Paul Ellison
  Updated: 25 Feb 2015 - Cleaned up code


  You must select MIDI from the "Tools > USB Type" menu
  To view the raw MIDI data on Linux: aseqdump -p "Teensy MIDI"
*/


#include <Bounce.h>


// the MIDI channel number to send messages
const int channel = 1;


int blinkGo = 0;
int blinkStop = 0;


int goLEDstate = HIGH;
int stopLEDstate = HIGH;


long previousGoMillis = 0;
long previousStopMillis = 0;


long goBlinkInt = 200;
long stopBlinkInt = 500;


int goLED = 2;
int stopLED = 3;
int nextLED = 4;


// Create Bounce objects for each button.  The Bounce object
// automatically deals with contact chatter or "bounce", and
// it makes detecting changes very simple.
Bounce goButton = Bounce(10, 5);
Bounce stopButton = Bounce(11, 5);
Bounce nextButton = Bounce(12, 5);


void setup() {
  // Setup input pins for "active low"
  pinMode(10, INPUT_PULLUP);
  pinMode(11, INPUT_PULLUP);
  pinMode(12, INPUT_PULLUP);

  // Setup output pins
  pinMode(goLED, OUTPUT);
  pinMode(stopLED, OUTPUT);
  pinMode(nextLED, OUTPUT);

  // Set initial LED values.
  digitalWrite(goLED, HIGH);
  digitalWrite(stopLED, HIGH);
}


void loop() {
  // Update all the buttons.
  goButton.update();
  stopButton.update();
  nextButton.update();


  // Check each button for "falling" edge.
  // Send a 'MIDI Note On' message when each button is pressed
  if (goButton.fallingEdge()) {
    usbMIDI.sendNoteOn(62, 99, channel);  // 62 = D4
    blinkGo = 4;
  }

  if (stopButton.fallingEdge()) {
    usbMIDI.sendNoteOn(63, 99, channel);  // 63 = D#4
    if (blinkStop == 0) {
      blinkStop = 6;
    } else {
      blinkStop = 0;
      digitalWrite(stopLED, HIGH);
    }
  }

  if (nextButton.fallingEdge()) {
    usbMIDI.sendNoteOn(64, 99, channel);  // 64 = E4
    digitalWrite(nextLED, LOW);
  }

  // Check each button for "rising" edge
  // Send a 'MIDI Note Off' message when each button is released
  if (goButton.risingEdge()) {
    usbMIDI.sendNoteOff(62, 0, channel);  // 62 = D4
  }
  if (stopButton.risingEdge()) {
    usbMIDI.sendNoteOff(63, 0, channel);  // 63 = D#4
  }
  if (nextButton.risingEdge()) {
    usbMIDI.sendNoteOff(64, 0, channel);  // 64 = E4
    digitalWrite(nextLED, HIGH);
  }


  // MIDI Controllers should discard incoming MIDI messages.
  // Read more at the following url:
  // http://forum.pjrc.com/threads/24179-Teensy-3-Ableton-Analog-CC-causes-midi-crash
  while (usbMIDI.read()) {
    // Ignore incoming messages
  }

  unsigned long currentGoMillis = millis();
  unsigned long currentStopMillis = millis();

  if ((blinkGo > 0) || (goLEDstate == LOW)) {
    if(currentGoMillis - previousGoMillis > goBlinkInt) {
      // save the last time you blinked the LED
      previousGoMillis = currentGoMillis;  


      // if the LED is off turn it on and vice-versa:
      if (goLEDstate == LOW) {
        goLEDstate = HIGH;
      } else {
        goLEDstate = LOW;
      }
      // set the LED with the ledState of the variable:
      digitalWrite(goLED, goLEDstate);
      blinkGo--;
    }
  }

  if ((blinkStop > 0) || (stopLEDstate == LOW)) {
    if(currentStopMillis - previousStopMillis > stopBlinkInt) {
      // save the last time you blinked the LED
      previousStopMillis = currentStopMillis;  


      // if the LED is off turn it on and vice-versa:
      if (stopLEDstate == LOW) {
        stopLEDstate = HIGH;
      } else {
        stopLEDstate = LOW;
      }
      // set the LED with the ledState of the variable:
      digitalWrite(stopLED, stopLEDstate);
      blinkStop--;
    }
  }
}

 

An improved version of the controller is in progress, build and code to follow in an additional post.

 

Would be interested to hear if anybody has any comments/suggestions/improvement ideas for the code (or project as a whole). Any additions will be credited. image

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube