Click here to Skip to main content
15,881,588 members
Articles / Programming Languages / C

Arduino-Based MIDI Expression Pedal

Rate me:
Please Sign up or sign in to vote.
4.99/5 (46 votes)
17 Jul 2009CPOL10 min read 161.3K   807   49  
Create a MIDI expression pedal with an Arduino circuit board
/*
 * Metronome2
 *
 * Based on the basic Arduino example, Blink:
 *   http://www.arduino.cc/en/Tutorial/Blink
 * Operates as a visual metronome.
 */
 
// Constants
const int LED_PIN = 13;					// LED connected to digital pin 13
const int POT_PIN = 0;					// Pot connected to analog pin 0
const int POT_THRESHOLD = 7;			// Threshold amount to guard against false values


void setup()							// Run once, when the sketch starts
{
	pinMode(LED_PIN, OUTPUT);			// Sets the digital pin as output
}

void loop()								// Run over and over again
{
	int nCurrentPotValue = analogRead(POT_PIN);
	int nTempo = map(nCurrentPotValue, 0, 1023, 50, 255);		// Map the value to 50-255

	// Delay in milliseconds = 1 minute    60 seconds   1000 milliseconds
	//                         --------- * ---------- * -----------------
	//                         (X) beats   minute       second

	int nDelay = (int)((60.0 * 1000.0) / (float)nTempo);
	PlayNote(nDelay);
}

void PlayNote(int nDuration)
{
	nDuration = (nDuration / 2);
	digitalWrite(LED_PIN, HIGH);		// Set the LED on
	delay(nDuration);					// Wait for half the (original) duration
	digitalWrite(LED_PIN, LOW);			// Set the LED off
	delay(nDuration);					// Wait for half the (original) duration
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United States United States
In a nutshell, my forte is Windows, Macintosh, and cross-platform development, and my interests are in UI, image processing, and MIDI application development.

Comments and Discussions