Piezo Code
' THE CODE FOR THE TUBE GRUBE ' This will program a tube that has ' both piezo sensors as well as one ' pressure sensor. The pressure sensor ' will control the velocity and the ' piezo sensors will control the sounds that ' are triggered by the midi module.

' Bennett, Joanna, Teresa '**************************************

'#SET DEFINES AND PORTS# DEFINE ADC_BITS 10 DEFINE ADC_CLOCK 3 ' Set sampling time in microseconds DEFINE ADC_SAMPLEUS 10 TRISA = %11111111 ' set all of port A to input ADCON1? = %10000010 tx var portc.6 ' serial constants and pin assignments! : rx var portc.7 'put in midi shit here, not sure if below line is right n9600 con 16468

'#DEFINE VARIABLES# pressureVar VAR WORD ' Create variable to store result pressureVar2 var word result var word pressureResult var word innerPiezo var word outerPiezo var word velocity var word lastInner var word lastOuter var word

' initialize switch variables

  innerPiezo = lastinner
  outerpiezo = lastouter

'#MAIN PROGRAM# main:

    'read in data  
    ADCIN 0, pressurevar          ' Read! in pin 0
    'do we need pauses here?
    adcin 1, pressureVar2         ' Read in pin 1
    adcin 2, innerPiezo           ' Read in pin 2 for inner data
    adcin 3, outerPiezo           ' Read in pin 3 for outer data

    'pressure sensor code  
    result = abs(pressureVar - pressureVar2)' take diff between 2 inputs
    pressureResult = result * 8   ' multiply by 8 for larger range
    SEROUT2? tx, n9600, [DEC result, 10, 13]


    'inner piezo code
    if innerPiezo != lastInner then      'if there has been a change of state
    Pause 10                      ' let the ADC chill again
        if innerPiezo != 0 then         'see if there is any vibration from piezo has been pushed 
        serout2 txpin, 12, [144, innerPiezo, pressureResult] 'note on, at innerPiezo value, pressureResult velocity
        endif
        innerPiezo = lastInner          'for change of state
    endif

    'outer piezo code
    if outerPiezo != lastOuter then      'if there has been a change of state
    Pause 10                      'let the ADC chill again
        if outerPiezo != 0 then         'see if there is any vibration from piezo has been pushed 
        serout2 txpin, 12, [144, outerPiezo, pressureResult] 'note on, at innerPiezo value, pressureResult velocity
        serout2 txpin, 12, [144, outerPiezo, 0]              'note off
        '--don't forget to turn the note off--
        endif
        outerPiezo = lastOuter          'for change of state
    endif          

GoTo? main
Back


Page last modified April 11, 2006, at 10:17 PM