' Useful Constants Private Const debugVar As Boolean = true Private Const initialDelay As Single = 0.5 Private Const runningPin As Byte = 9 ' Global Vars dim xPoint1 As Integer dim yPoint1 As Integer dim xPoint2 As Integer dim yPoint2 As Integer dim xPoint1Low As Integer dim xPoint1High As Integer dim yPoint1Low As Integer dim yPoint1High As Integer dim xPoint2Low As Integer dim xPoint2High As Integer dim yPoint2Low As Integer dim yPoint2High As Integer ' Midi Setup dim inputBuffer(1 To 13) As Byte dim outputBuffer(1 To 10) As Byte dim midiCmd As Byte dim midiCmdValue1 As Byte dim midiCmdValue2 As Byte dim octaveVar As Byte dim noteVar As Byte dim currentProgram As Byte dim noteOn As Boolean ' Midi Constants Private Const MIN_NOTE As Integer = 15 Private Const MAX_NOTE As Integer = 120 'Private Const MIN_OCTAVE As Integer = 2 'Private Const MAX_OCTAVE As Integer = 8 Private Const MAX_VELOCITY As Integer = 100 Private Const MIN_VELOCITY As Integer = 1 Private Const MIN_PITCH_BEND As Integer = 1 Private Const MAX_PITCH_BEND As Integer = 127 Private Const MAX_PROGRAM As Integer = 127 Private Const MIN_PROGRAM As Integer = 1 Private Const START_PROGRAM As Byte = 40 Private Const NOTE_ON As Byte = 144 Private Const NOTE_OFF As Byte = 144 Private Const PROGRAM_CHANGE As Byte = 192 Private Const PITCH_BEND As Byte = 224 ' Board Setup Constants Private Const xPin1 As Byte = 15 Private Const yPin1 As Byte = 14 Private Const readPin1 As Byte = 13 Private Const xPin2 As Byte = 18 Private Const yPin2 As Byte = 17 Private Const readPin2 As Byte = 16 sub main () call delay(initialDelay) ' start program with a half-second delay call putPin(runningPin,1) ' tell the world I am running ' Serial buffers: call openQueue(inputBuffer, 13) call openQueue(outputBuffer, 10) ' Open serial port on COM1: call openCom(1, 9600, inputBuffer, outputBuffer) ' Set baud rate to 30,270 for MIDI register.ubrr = 14 midiCmd = PROGRAM_CHANGE midiCmdValue1 = START_PROGRAM 'midiCmdValue2 = CURRENT_PROGRAM if debugVar = false then call putQueue(OutputBuffer, midiCmd, 1) call putQueue(OutputBuffer, midiCmdValue1, 1) 'call putQueue(OutputBuffer, midiCmdValue2, 1) end if ' Set initial range vars xPoint1High = 0 xPoint1Low = 100 yPoint1High = 0 yPoint1Low = 100 xPoint2High = 0 xPoint2Low = 100 yPoint2High = 0 yPoint2Low = 100 'octaveVar = CByte(MIN_OCTAVE) noteOn = false do ' Get X Value call putPin(yPin1,0) call putPin(xPin1,1) call putPin(yPin2,0) call putPin(xPin2,1) xPoint1 = getADC(readPin1) xPoint2 = getADC(readPin2) call putPin(yPin1,0) call putPin(xPin1,0) call putPin(yPin2,0) call putPin(xPin2,0) ' Get Y Value call putPin(xPin1,0) call putPin(yPin1,1) call putPin(xPin2,0) call putPin(yPin2,1) yPoint1 = getADC(readPin1) yPoint2 = getADC(readPin2) if xPoint1 > 0 then if yPoint1 > 0 then if xPoint1 > xPoint1High then xPoint1High = xPoint1 end if if xPoint1 < xPoint1Low then xPoint1Low = xPoint1 end if if yPoint1 > yPoint1High then yPoint1High = yPoint1 end if if yPoint1 < yPoint1Low then yPoint1Low = yPoint1 end if if noteOn = false then xPoint1 = intRanger(xPoint1Low, xPoint1High, MIN_NOTE, MAX_NOTE, xPoint1) yPoint1 = intRanger(yPoint1Low, yPoint1High, MIN_VELOCITY, MAX_VELOCITY, yPoint1) midiCmd = NOTE_ON 'noteVar = cByte(xPoint1) * octaveVar noteVar = cByte(xPoint1) 'velocityVar = cByte(yPoint1) midiCmdValue2 = cByte(yPoint1) if debugVar = false then call putQueue(OutputBuffer, midiCmd, 1) call putQueue(OutputBuffer, noteVar, 1) call putQueue(OutputBuffer, midiCmdValue2, 1) end if noteOn = true if debugVar = true then debug.print "x1: ";CStr(xPoint1) debug.print "y1: ";CStr(yPoint1) end if elseif noteOn = true then xPoint1 = intRanger(xPoint1Low, xPoint1High, MIN_PITCH_BEND, MAX_PITCH_BEND, xPoint1) yPoint1 = intRanger(yPoint1Low, yPoint1High, MIN_PITCH_BEND, MAX_PITCH_BEND, yPoint1) midiCmd = PITCH_BEND midiCmdValue1 = cByte(xPoint1) midiCmdValue2 = cByte(yPoint1) if debugVar = false then call putQueue(OutputBuffer, midiCmd, 1) call putQueue(OutputBuffer, midiCmdValue1, 1) call putQueue(OutputBuffer, midiCmdValue2, 1) end if if debugVar = true then debug.print "x1: ";CStr(xPoint1) debug.print "y1: ";CStr(yPoint1) end if end if end if else if noteOn = true then midiCmd = NOTE_OFF 'velocity = 0 midiCmdValue2 = 0 if debugVar = false then call putQueue(OutputBuffer, midiCmd, 1) call putQueue(OutputBuffer, noteVar, 1) call putQueue(OutputBuffer, midiCmdValue2, 1) end if noteOn = false end if end if if xPoint2 > 0 then if yPoint2 > 0 then if xPoint2 > xPoint2High then xPoint2High = xPoint2 end if if yPoint2 < xPoint2Low then xPoint1Low = xPoint2 end if if yPoint2 > yPoint2High then yPoint2High = yPoint2 end if if yPoint2 < yPoint2Low then yPoint2Low = yPoint2 end if xPoint2 = intRanger(xPoint2Low, xPoint2High, MIN_PROGRAM, MAX_PROGRAM, xPoint2) yPoint2 = intRanger(yPoint2Low, yPoint2High, MIN_NOTE, MAX_NOTE, yPoint2) 'octaveVar = CByte(xPoint2) currentProgram = CByte(xPoint2) midiCmd = PROGRAM_CHANGE midiCmdValue1 = currentProgram 'midiCmdValue2 = CURRENT_PROGRAM if debugVar = false then call putQueue(OutputBuffer, midiCmd, 1) call putQueue(OutputBuffer, midiCmdValue1, 1) 'call putQueue(OutputBuffer, midiCmdValue2, 1) end if if debugVar = true then debug.print "x2: ";CStr(xPoint2) debug.print "y2: ";CStr(yPoint2) end if end if end if ' Adjust for slope - how? - ' Check for historesis ' Check for distance ' Check for time call putPin(yPin1,0) call putPin(xPin1,0) call putPin(yPin2,0) call putPin(xPin2,0) loop end sub Function intRanger(byVal originalMin as integer, byVal originalMax as integer, byVal newMin as integer, byVal newMax as integer, byVal currentValue as integer) as integer dim zeroRefOriginalMax as long dim zeroRefNewMax as long dim zeroRefCurVal as long ' Check for out of range currentValues if (currentValue < originalMin) then currentValue = originalMin end if if (currentValue > originalMax) then currentValue = originalMax end if ' Zero Refference the values zeroRefOriginalMax = clng(originalMax - originalMin) zeroRefNewMax = clng(newMax - newMin) zeroRefCurVal = clng(currentValue - originalMin) ' Check for negative values and 0 max ranges if ( (zeroRefNewMax < 1) OR (zeroRefOriginalMax < 1) OR (originalMin < 0) OR (originalMax < 1) OR (newMin < 0) OR (newMax < 1) OR (currentValue < 0) ) then intRanger = 0 Exit Function end if intRanger = cint( ( (zeroRefCurVal * zeroRefNewMax) \ (zeroRefOriginalMax) ) + clng(newMin) ) End Function