---------BX24 code for <Virtual Flesh> with midi connection ------

Qprox1 = getADC(13)--fragment 6 - notevar 55
Qprox2 = getADC(14)--fragment 5 - notevar 60
Qprox3 = getADC(15)--fragment 1 - notevar 75
Qprox4 = getADC(16)--fragment 2 - notevar 80
Qprox5 = getADC(17)--fragment 7 - notevar 50
Qprox6 = getADC(18)--fragment 8 - notevar 45
Qprox7 = getADC(19)--fragment 3 - notevar 70
Qprox8 = getADC(20)--fragment 4 - notevar 65

dim inputBuffer(1 To 13) As Byte
dim outputBuffer(1 To 10) As Byte
dim midiCmd as byte
dim velocity as byte

Sub main()
call delay(0.5) ' start program with a half-second delay

dim noteVar as byte
dim Qprox1 as integer
dim Qprox2 as integer
dim Qprox3 as integer
dim Qprox4 as integer
dim Qprox5 as integer
dim Qprox6 as integer
dim Qprox7 as integer
dim Qprox8 as integer

' set up serial buffers:
call openQueue(inputBuffer, 13)
call openQueue(outputBuffer, 10)

call openCom(1, 9600, inputBuffer, outputBuffer) ' open serial port on COM1:
register.ubrr = 14 ' set baud rate to 30,270:
' call openCom(1, 30270, inputBuffer, outputBuffer)

do

Qprox1 = getADC(13)
Qprox2 = getADC(14)
Qprox3 = getADC(15)
Qprox4 = getADC(16)
Qprox5 = getADC(17)
Qprox6 = getADC(18)
Qprox7 = getADC(19)
Qprox8 = getADC(20)

'Qprox1 = getADC(13)--fragment 6 - notevar 55
'Qprox2 = getADC(14)--fragment 5 - notevar 60
'Qprox3 = getADC(15)--fragment 1 - notevar 75
'Qprox4 = getADC(16)--fragment 2 - notevar 80
'Qprox5 = getADC(17)--fragment 7 - notevar 50
'Qprox6 = getADC(18)--fragment 8 - notevar 45
'Qprox7 = getADC(19)--fragment 3 - notevar 70
'Qprox8 = getADC(20)--fragment 4 - notevar 65

' get a note range from 36 to 96
' sent a noteon message, channel 1, velocity 64:

if ( Qprox1 > 400 ) then ' touch on Qprox1
noteVar = 55
midiCmd = 144
velocity = 64

elseif ( Qprox2 > 400 ) then ' touch on Qprox2
noteVar = 60
midiCmd = 144
velocity = 64

elseif ( Qprox3 > 400 ) then ' touch on Qprox3
noteVar = 75
midiCmd = 144
velocity = 64

elseif ( Qprox4 > 400 ) then ' touch on Qprox4
noteVar = 80
midiCmd = 144
velocity = 64

elseif ( Qprox5 = 0 ) then ' touch on Qprox5
noteVar = 50
midiCmd = 144
velocity = 64

elseif ( Qprox6 = 0 ) then ' touch on Qprox6
noteVar = 45
midiCmd = 144
velocity = 64

elseif ( Qprox7 = 0 ) then ' touch on Qprox7
noteVar = 70
midiCmd = 144
velocity = 64

elseif ( Qprox8 = 0 ) then ' touch on Qprox8
noteVar = 65
midiCmd = 144
velocity = 64

else
' sent a noteoff message, channel 1, velocity 64:
noteVar = 30 '----?
midiCmd = 144
velocity = 0

end if

' if (FSR1 > 5) then 'if (FSR1 > 5) And (FSR1 < 1023) then ' touch off
' noteVar1 = cByte((getADC(13) mod 60) + 36)

'debug.print "noteVar = " ; cstr(noteVar)
' when I want to see noteVar on the midi, I should delete this line,
' because midi also use a same port, COM1, like basic x


call putQueue(OutputBuffer, midiCmd, 1)
call putQueue(OutputBuffer, noteVar, 1)
call putQueue(OutputBuffer, velocity, 1)
call delay(0.5)


loop
end sub