Hardware Reference
In-Depth Information
Of course, you can't
be a self-respecting
MIDI enthusiast until you've built your
first theremin. It's like calling yourself a
writer before you've written your auto-
biography—it's just not done! Waving at
a distance ranger to make notes is a rite
of passage in MIDI-land. So, here's your
first MIDI theremin program. This one's
a bit different than most, as you'll see.
Wave at It
/*
Stinger player
Context: Arduino
*/
#include <SoftwareSerial.h>
// set up a software serial port to send MIDI:
SoftwareSerial midi(2, 3);
const int midiResetPin = 4; // Musical instrument shield's reset pin
const int threshold = 100; // sensor threshold
int lastReading = 0; // last sensor reading
The global variables include a threshold
setting for the infrared ranger, and a
variable to hold the previous reading.
void setup() {
// initialize hardware serial and MIDI serial:
Serial.begin(9600);
midi.begin(31250);
setup() opens communications and
resets the shield.
// reset the musical instrument shield:
resetMidi(midiResetPin);
}
MADE
IN I TALY
Figure 11-5
Spark Fun Musical Instrument shield
attached to an Arduino and an
infrared ranger. The 100µF capacitor
smoothes the sensor's readings a bit,
but it's optional if your sensor gives
reliable readings without it.
DIGITAL (PWM ~ )
- +
L
UNO
ON
TX
RX
ARDUINO
RESET
ICSP
POWER
ANALOG IN
Analog In
Search WWH ::




Custom Search