'MIDI.BS2 - MIDI out program for BASIC Stamp II. 'Copyright 1997-2000 Jeff Mann jefman@utcc.utoronto.ca 'Free for non-commercial use - may not be published or reproduced. 'Get the latest version or add links to: ' http://www.interaccess.org/arg/arg-knowledge/MIDI.BS2 'Stamp II only - Stamp I serial port is not fast enough for MIDI. 'MIDI-out only - Stamp may have trouble receiving MIDI-in because serial 'port is unbuffered. MIDI-in is not covered here. 'This program measures up to 15 potentiometers or other 'resistive sensors, and sends out 7- or 14-bit MIDI controller data. 'Easily modified to send note or pitchbend data instead. The values 'are not normalized to full-scale; you'll have to add code for that 'or do it in the receving program, eg. Max., taking into account the 'particular sensor you're using. ' 'See the RCTime command in the Stamp manual for the wiring diagram 'to hook up the pots. Here is the circuit for the MIDI out connector: ' ' ' rear view of MIDI out jack ' ___ ___ ' +5 volts / l_l \ ' | / \ ' | NC l o1 3o l NC ' | \ o4 2 5o / ' |__/\/\/______\_| o |_/___/\/\/_____> to Stamp data pin ' 220 ohms \___|___/ 220 ohms ' | ' _l_ ' /// ' ground ' ' 'Comment out DEBUG statments for faster response. 'constants, shouldn't change these midibaudmode con 32780 '31.25kb, 8n1, non-inverted, open collector 'for 14-bit controllers - controller 32 is lsb of controller 0, etc. controllerLSBoffset con 32 'MIDI status bytes: controller con %10110000 + midichannel noteon con %10010000 + midichannel pitchbend con %11100000 + midichannel 'declare variables value var word 'holds the 16-bit value read from the pot pin var nib 'which pin/pot we are reading at the moment statusbyte var byte 'MIDI status; controller, noteon, or pitchbend data1 var byte 'first data byte, eg. controller or note number data2 var byte 'second MIDI data byte, eg. value or velocity 'user configuration - adjust these to suit you 'DANGER - check your circuitry and configure pins accordingly!! 'set unused pins to outputs DIRS = %1111111111111111 'all outs OUTS = %0000000000000000 'all low midichannel con 1 'MIDI transmit channel midioutpin con 0 'pin connected to MIDI out connector 'check the MIDI spec for a list of controller numbers you can use controlleroffset con 0 'add to pot's pin # to get MIDI controller # hipot con 15 'highest pin with a pot to measure lowpot con 14 'lowest pin with a pot to measure doit: debug HOME for pin = lowpot to hipot 'read the value of the pot high pin pause 1 rctime pin, 1, value debug "pot ", DEC pin, " reads ", DEC value, CR value = value >> 1 'drop the least significant bit 'send most significant 7 bits as continuous controller msg statusbyte = controller 'sending controller message data1 = pin + controlleroffset 'controller # data2 = value.highbyte serout midioutpin, midibaudmode, [statusbyte, data1, data2] ''uncomment this section to send 14-bit controller data ''send least significant 7 bits 'data1 = data1 + controllerLSBoffset 'data2 = value.lowbyte 'data2 = data2 >> 1 'convert to 7 bits ''use running status byte (can leave it out if unchanged) 'serout midioutpin, midibaudmode, [data1, data2] next goto doit