'{$stamp bs2} '** MIDIBreathSensor - Adam Overton with contributions from others '** This patch sends out midi signals that map the following: '** -MIDIchannel1-> shape of the breath (continuous controller) '** -MIDIChannel2-> beginning and ending of breath (NoteOn-amp=1/Off-amp=0) '** -MIDIChannel3-> monkey Mind - use button to signal thoughts (NoteOn-amp=1/Off-amp=0) 'comment out DEBUG statements for faster response. '---------------------------------- 'CONSTANTS - shouldn't change these midibaudmode con 32780 '31.25kb, 8n1, non-inverted, open collector '---------------------------------- 'MIDI status byte ONE: controller con 176 noteOn con 144 '---------------------------------- 'declare VARIABLES 'value var word 'holds the 16-bit value read from the pot sensorIn var word 'holds the 16-bit value read from the pot sensorDATA var word 'sensor info after MIDI value conversion mindTrig var bit 'button value holder lastVal var byte 'value from last polling period lastButtVal var bit 'value from button's last polling period pin var nib 'which pin/pot we are reading at the moment '---------------------------------- '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 midichan var nib 'MIDI transmit channel midioutpin con 15 'pin connected to MIDI out connector controlleroffset con 7 'MIDI controller # - 7 is for ccGain hipot con 0 'highest pin with a pot to measure lowpot con 0 'lowest pin with a pot to measure '---------------------------------- 'ROUTINE main: 'debug HOME '------ MONKEY MIND TRIGGER AREA '------ channel 3: monkeyMind Trigger midiChan = 3 GOSUB monkeyMindTrigger 'Midi Note-on/off for start/end of breath '------ RESPIRATION PRESSURE SENSOR AREA for pin = lowpot to hipot 'read the value of the pot high pin pause 1 rctime pin, 1, sensorIn '------ convert sensor data into usable MIDI values sensorDATA = 65535 - (sensorIn - 1) sensorDATA = ((sensorDATA / 128) min 384) - 384 if sensorDATA = lastVal then main 'if value is the same, don't worry about 'spitting it out again - wait til it's 'different '------ channel 1: ccBreath midiChan = 1 GOSUB bigBreath 'Midi Breath as continuous controller '------ channel 2: breathON/OFF midiChan = 2 GOSUB breathStartStop 'Midi Note-on/off for start/end of breath 'debug ? sensorDATA, CR 'pause 1000 lastVal = sensorDATA 'stores curr. sensorValue for comparison in ' next control period next 'only used if more than one input device goto main '----------------------------------------- '----------------------------------------- '///// breath sent as continuous controller signal (0-127) bigBreath: serout midioutpin, midibaudmode, [controller+midiChan-1, controllerOffset, sensorDATA] RETURN '----------------------------------------- '///// breath start sent as NoteON, stop as NoteOFF breathStartStop: 'if sensor was Zero and now is not, then noteON if lastVal = 0 AND sensorDATA <> 0 THEN bStartMSG 'if sensor was Not Zero and now IS Zero, then noteOFF if lastVal <> 0 AND sensorDATA = 0 THEN bStopMSG 'else - if neither case applies go back to main and continue RETURN bStartMSG: serout midioutpin, midibaudmode, [noteOn+midiChan-1, 0, 1] RETURN bStopMSG: 'zero amplitude sends noteOFF serout midioutpin, midibaudmode, [noteOn+midiChan-1, 0, 0] RETURN '----------------------------------------- '///// MONKEY MIND TRIGGER - sent as NOTEON/OFF ON NOTE WITH SAME CH.# monkeyMindTrigger: 'mindTrig = in1 'indicate which pin is getting testing mindTrig = in7 'indicate which pin is getting testing '**4/23/03- changed to in7 because of wiring messup on board if mindTrig=1 AND mindTrig<>lastButtVal THEN buttonSend goto doNothing 'if test fails, go back buttonSend: 'debug ? mindTrig 'send out bang on note with same number as midi transmit channel serout midioutpin, midibaudmode, [noteOn+midiChan-1, 0, 1] 'noteON pause 10 'not having a pause between noteON/OFF might be confusing SC serout midioutpin, midibaudmode, [noteOn+midiChan-1, 0, 0] 'noteOFF doNothing: lastButtVal = mindTrig RETURN '-----------------------------------------