'{$STAMP BS2SX} '' '' Programmer: Craig Stuart Sapp '' Creation Date: Sun 07-11-1999 '' Last Modified: Tue 07-13-1999 '' Filename: cout.bsx '' Syntax: Basic Stamp IIsx '' '' Description: This program sends out the MIDI note middle C '' once every second. The note remains on for '' 1/2 of a second, and then is turned off for '' 1/2 of a second. '' The MIDI note-on message is [$90, 60, 127], where '' $90 = 144 = MIDI note-on command '' 60 = Middle C as a MIDI note number '' 127 = attack velocity (very loud) '' The MIDI note-off message is [$90, 60, 0], where '' $90 = a MIDI note-on command unless velocity is 0 '' 60 = the MIDI key to turn off '' 0 = attack velocity of zero (i.e., turn note off) '' '' The MIDI Output Circuit connected between 5v power and pin 8 is: '' +5V to 220 Ohm to MIDI 2; MIDI 4 to 220 Ohm to a pin. '' outpin con 8 ' output pin on which to send MIDI data baudmode con 60 ' baude mode for serout: (2500000/31250)-20 msec ' note that this value should be 12 for BS2. ' Serial rate for MIDI is 31,250 data bits/sec. outpause con 0 ' pause time in units of 0.4 millisec between bytes ' on the BS2, units are 1.0 millisec ' According to BASIC Stamp Programming Manual v1.9, page 208: ' "Unused pins that are not connected to circuitry should be set to output" ' to minimize power consumption. ' which is done here: DIRS = %1111111111111111 ' Don't set pins connected to input circuitry to be output, or you can ' damage the Basic Stamp. top: serout outpin, baudmode, outpause, [$90, 60, 127] pause 493 serout outpin, baudmode, outpause, [$90, 60, 0] pause 492 goto top: ' Note that the pause times of 493 and 492 are the values ' needed (found empirically) to get a total period of ' 1000 milliseconds for the loop. A three-byte MIDI message ' takes about 1 millisecond to send.