'{$STAMP BS2SX} '' '' Programmer: Craig Stuart Sapp '' Creation Date: Wed Apr 2 19:29:26 PST 2003 '' Last Modified: Fri Apr 4 21:21:12 PST 2003 '' Filename: switch1.bsx '' Syntax: Basic Stamp IIsx '' '' Description: This program monitors an on/off switch. '' If the switch is turned on, a middle note C '' is played. If the switch is turned off, then '' the note is turned off. '' inpin con INS.bit7 ' input pin to monitor switch state on. midioutpin con 8 ' output pin on which to send MIDI data midirate 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. ' 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: ' using IN7: DIRS = %1111111101111111 ' Don't set pins connected to input circuitry to be output, or you can ' damage the Basic Stamp. on: if inpin = 1 then on gosub midion ' debug "switch was closed", cr off: if inpin = 0 then off gosub midioff ' debug "switch was opened", cr goto on midion: serout midioutpin, midirate, [$90, 60, 64] return midioff: serout midioutpin, midirate, [$90, 60, 0] return