Shop OBEX P1 Docs P2 Docs Learn Events
simple switch to midi — Parallax Forums

simple switch to midi

ArchiverArchiver Posts: 46,084
edited 2002-07-11 03:12 in General Discussion
I am a new user of the stamp; The project that I am taking on is pretty
simple....All I want to do is send a on/off signal from analog switch to a
midi signal.....
Can anyone tell me where I could find schematics and code to do this?

Thanks in advance for any help...

t



_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-07-11 03:12
    Hello,
    Here's a conglomeration of my notes of different basic stamp midi pages.
    There should be lots of help in this. Please report back of your
    success, and also I would appreciate any additional stamp midi links.

    -pj

    Basic Stamp II MIDI input/output

    This program demonstrates how to get MIDI output using a Basic Stamp
    IIsx.

    The circuit connected to the Basic Stamp is shown below. The +5v power
    source for the circuit below comes from the DIP pin #21. The program
    uses I/O pin #8 (DIP pin #13) for the MIDI output, but you can change
    the program to use any output pin for MIDI out. The buffer op-amp does
    not seem to be necessary.

    The primary function used in this program is the serout function. The
    first parameter to serout is the output pin (0-15,16). The second
    parameter is the baude mode which is set to the value 2,500,000/31,250 -
    20 = 60. Where 31,250 is the data bit rate of the MIDI serial protocol.


    '{$STAMP BS2SX}
    ''
    '' Programmer: Craig Stuart Sapp
    '' Creation Date: Sun 07-11-1999
    '' Last Modified: Tue 07-13-1999
    '' Filename: cout.bsx
    '' Syntax: Basic Stamp IIsx
    ''
    '' Description: This program sends out the MIDI note middle C
    '' once every second. The note remains on for
    '' 1/2 of a second, and then is turned off for
    '' 1/2 of a second.
    '' The MIDI note-on message is [noparse][[/noparse]$90, 60, 127], where
    '' $90 = 144 = MIDI note-on command
    '' 60 = Middle C as a MIDI note number
    '' 127 = attack velocity (very loud)
    '' The MIDI note-off message is [noparse][[/noparse]$90, 60, 0], where
    '' $90 = a MIDI note-on command unless velocity is 0
    '' 60 = the MIDI key to turn off
    '' 0 = attack velocity of zero (i.e., turn note off)
    ''
    '' The MIDI Output Circuit connected between 5v power and pin 8 is:
    '' +5V to 220 Ohm to MIDI 2; MIDI 4 to 220 Ohm to a pin.
    ''

    outpin con 8 ' output pin on which to send MIDI data
    baudmode 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.
    outpause con 0 ' pause time in units of 0.4 millisec between bytes
    ' on the BS2, units are 1.0 millisec

    ' 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:
    DIRS = %1111111111111111
    ' Don't set pins connected to input circuitry to be output, or you can
    ' damage the Basic Stamp.


    top:
    serout outpin, baudmode, outpause, [noparse][[/noparse]$90, 60, 127]
    pause 493
    serout outpin, baudmode, outpause, [noparse][[/noparse]$90, 60, 0]
    pause 492
    goto top:

    ' Note that the pause times of 493 and 492 are the values
    ' needed (found empirically) to get a total period of
    ' 1000 milliseconds for the loop. A three-byte MIDI message
    ' takes about 1 millisecond to send.
    ( http://devices.sapp.org/micro/stamp2sx/cout/cout.bsx)



    result var word
    tabval var word
    tabval2 var word



    input 1

    noteon var word

    rcheck
    high 0
    pause 1
    RCTIME 0,1,result
    if result < 223 and result > 0 then send

    goto rcheck

    send: lookdown
    result,<=[noparse][[/noparse]1,2,8,15,20,25,33,37,45,49,54,62,67,73,78,85,93,98,103,110,117
    ,122,129,135,140,145,152,158,164,170,175,182,188,194,200,205,213,220,225
    ],tabval
    serout 7, $8000+12, [noparse][[/noparse]144,tabval+20,127] 'the resistor value won't be the
    same
    gosub send2 ' every time, so you gotta
    serout 7, $8000+12, [noparse][[/noparse]128,tabval+20,127] ' pick the highest value that it
    shows up
    return ' as through trial n error to make your table
    send2: high 0
    pause 1
    RCTIME 0,1,noteon
    if noteon > 225 then send3
    lookdown
    noteon,<=[noparse][[/noparse]1,2,8,15,20,25,33,37,45,49,54,62,67,73,78,85,93,98,103,110,117
    ,122,129,135,140,145,152,158,164,170,175,182,188,194,200,205,213,220,225
    ],tabval2

    if tabval2=tabval then send
    return
    send3:
    noteon = result ' this takes care of an unacceptable value from the POT
    return ' measurement...

    ' this code could be much more elegant, but it works... lemme know if
    you do something
    ' cool w/it.
    ' thanks to Jon Radenberg's basic stamp2 "knob box" for the inspiration
    for this project
    ' http://www.geopath.com/~jraden/knobs.html



    ' MIDI CODE TX
    ' Programs to emit MIDI CODE from a BSII starting from the
    ' reading of three pots and four buttons
    ' DESCRIPTION:
    ' It is a console to send out MIDI code with four
    ' buttons for the emission of note_on code and three pots
    ' for the emission of control-change code (Main Volume - Bread and
    ' Expression) .A selection button
    ' allows, by means of successive pulsations to select among those
    ' analogical entrances with the pots and the digital inputs from the
    buttons in
    ' in two banks of four buttons.The midi code emission is always made in
    the one
    ' channel 0 and the notes correspond the C3 (36) from now on.
    ' The selection recycles among 5 steps: 1) four low buttons, 2) four
    high buttons.
    ' 3) pot 1, 4) Joystick with two pots, 5) 3th Pot and joystick
    ' Roberto Gomez [noparse]/noparse][url=http://forums.parallaxinc.com/group/basicstamps/post?postID=WdjR0L1EX9GsmZ_biOCg772i3C3MSoZwA2oCeqHAlNRK9FMXqczg6otP2MbSFu5Ia_J-K_r2UJmwItQ]robby@a...[/url
    '
    '
    'HARDWARE:
    'P0 Joystick vertical pot
    'P1 Joystick Horizontal pot
    'P2 3th Pot
    '
    'P4 Joystick Led
    'P5 3th pot led
    'P6 First four buttons led
    'P7 Seconds four buttons led
    'P8 Input button 1
    'P9 Input button 2
    'P10 Input button 3
    'P11 Input button 4
    'P12 Selection button
    'P13 MIDI Output
    'P14 LCD Clock Only for debug
    'P15 LCD Data

    'VARIABLES:
    Display data 0,1,2,4,8,12
    Pot1 con 0
    Pot2 con 1
    Pot3 con 2
    LedPot1? con 4
    LedJoy? con 5
    LedBan1? con 6
    LedBan2? con 7
    Pul1 con 8
    Pul2 con 9
    Pul3 con 10
    Pul4 con 11
    Selec con 12
    Midiout con 13
    ClkLcd? con 14
    DataLcd? con 15
    Nota var byte
    Not1 var byte
    Not2 var byte
    Seleccion var nib 'Selector position
    x var nib
    y var word
    VarBut? var byte 'Button command var
    TipoMens? var byte 'Mensage type
    Dato var byte
    cuenta var word
    ValPot? var byte(3)
    Control var nib
    Leds var nib
    Sel var bit
    z var nib
    c var byte
    boton var nib

    'INICIALITATION:

    DIRS=%1110000011110000

    'The start is in the first four buttons bank


    Seleccion=0
    VarBut=0?
    Dato=$24 'First note

    serout Midiout,12,[noparse][[/noparse]$FA] 'Send Start (FAH)

    Main:

    loop:
    Button Selec,0,255,0,VarBut?,1,accion
    Seleccion = Seleccion + 1
    if Seleccion > 5 then otra
    read display+seleccion,c
    OutB? = c 'Correspondig led on
    pause 1000
    goto loop
    otra: Seleccion = 0:goto loop

    Accion: Pause 2000
    Seleccion = Seleccion - 1 'First Selection = 0
    Loopot: Branch Seleccion,[noparse][[/noparse]Accion1,Accion2,Pote1,Joy,JoyPot?]

    Accion1:
    x=8
    Loop1: Button x,0,255,0,VarBut?,1,boton1
    x=x+1
    if x>12 then accion1
    goto loop1
    boton1:
    x=x-8

    Branchon: Branch x,[noparse][[/noparse]Notaon1,Notaon2,Notaon3,Notaon4,main]
    goto main
    Branchoff1: Branch x,[noparse][[/noparse]Notaoff1,Notaoff2,Notaoff3,Notaoff4,main]
    goto main
    Notaon1:
    Nota = $24
    gosub EnvPulon?
    goto Levanta1
    Notaoff1:
    Nota =$24
    gosub EnvPulOff?
    goto accion1
    Notaon2:
    Nota = $25
    gosub EnvPulon?
    goto Levanta1
    Notaoff2:
    Nota =$25
    gosub EnvPulOff?
    goto accion1
    Notaon3:
    Nota = $26
    gosub EnvPulon?
    goto Levanta1
    Notaoff3:
    Nota =$26
    gosub EnvPulOff?
    goto accion1
    Notaon4:
    Nota = $27
    gosub EnvPulon?
    goto Levanta1
    Notaoff4:
    Nota =$27
    gosub EnvPulOff?
    goto accion1

    Accion2:
    x=8
    loop2: Button x,0,255,0,VarBut?,1,boton2
    x=x+1
    if x>12 then accion2
    goto loop2
    Boton2:
    x=x-8
    Branch x,[noparse][[/noparse]Notaon5,Notaon6,Notaon7,Notaon8,main]
    goto main
    Branchoff2: Branch x,[noparse][[/noparse]Notaoff5,Notaoff6,Notaoff7,Notaoff8,main]
    goto main

    Notaon5:
    Nota = $28
    gosub EnvPulon?
    goto Levanta2
    Notaoff5:
    Nota =$28
    gosub EnvPulOff?
    goto accion2

    Notaon6:
    Nota = $29
    gosub EnvPulon?
    goto Levanta2
    Notaoff6:
    Nota =$29
    gosub EnvPulOff?
    goto accion2

    Notaon7:
    Nota = $2A
    gosub EnvPulon?
    goto Levanta2
    Notaoff7:
    Nota =$2A
    gosub EnvPulOff?
    goto accion2

    Notaon8:
    Nota = $2B
    gosub EnvPulon?
    goto Levanta2
    Notaoff8:
    Nota =$2B
    gosub EnvPulOff?
    goto accion2

    Pote1:
    '3th Pot
    TipoMens? = $B0
    Control = 7 'Main Volumen
    x=2
    High Pot3
    Pause 1
    RCtime Pot3,1,cuenta
    If cuenta > 300 then bien
    cuenta = 300
    Bien: ValPot?(x) = cuenta - 300
    If NOT ValPot?(x)>127 then Sigue1
    ValPot?(x)=127
    sigue1: gosub EnvPot?
    goto Reci
    Joy:
    'Joystick Pot
    TipoMens? = $B1 'Canal 2
    Control = 10 'Pan Controller
    x=0
    High Pot1
    Pause 1
    RCtime Pot1,1,cuenta
    If cuenta > 300 then bien1
    cuenta = 300
    bien1: ValPot?(x) = cuenta - 300
    If NOT ValPot?(x)>127 then Sigue2
    ValPot?(x)=127
    sigue2: gosub EnvPot?
    TipoMens? = $B2 'Canal 3
    Control = 11 'Expression Controller
    x=1
    High Pot2
    Pause 1
    RCtime Pot2,1,cuenta
    If cuenta > 300 then bien2
    cuenta = 300
    bien2: ValPot?(x)=cuenta - 300
    If NOT ValPot?(x)>127 then Sigue3
    ValPot?(x)=127
    sigue3: gosub EnvPot?
    goto Reci
    JoyPot:?

    TipoMens? = $B1
    Control = 10
    x=0
    High Pot1
    Pause 1
    RCtime Pot1,1,cuenta
    If cuenta > 300 then bien3
    cuenta = 300
    bien3: ValPot?(x) = cuenta - 300
    If NOT ValPot?(x)>127 then Sigue4
    ValPot?(x)=127
    Sigue4: gosub EnvPot?
    TipoMens? = $B2
    Control = 11
    x=1
    High Pot2
    Pause 1
    RCtime Pot2,1,cuenta
    If cuenta > 300 then bien4
    cuenta = 300
    bien4: ValPot?(x) = cuenta - 300
    If NOT ValPot?(x)>127 then Sigue5
    ValPot?(x)=127
    Sigue5: gosub EnvPot?
    TipoMens? = $B0
    Control = 7
    x=2
    High Pot3
    Pause 1
    RCtime Pot3,1,cuenta
    If cuenta > 300 then bien5
    cuenta = 300
    bien5: ValPot?(x) = cuenta - 300
    If NOT ValPot?(x)>127 then Sigue6
    ValPot?(x)=127
    Sigue6: gosub EnvPot?

    Reci:
    C=IN12

    If C=0 then main

    goto loopot

    EnvPulon:?
    serout Midiout,12,[noparse][[/noparse]$93,Nota,64]
    'Debug "NOTAON:",hex Nota,13
    Return

    EnvPuloff:?
    serout Midiout,12,[noparse][[/noparse]$83,Nota,64]
    'Debug "NOTAOFF:",hex Nota,13
    Return

    EnvPot:?
    serout Midiout,12,[noparse][[/noparse]TipoMens?,Control,ValPot?(x)]
    'Debug hex TipoMens? ,? ValPot?(x),13
    Return

    Levanta1:
    z=x+8
    NoLev1:? Button z,1,255,0,VarBut?,0,NoLev1?
    Branch x,[noparse][[/noparse]Notaoff1,Notaoff2,Notaoff3,Notaoff4,main]

    Levanta2:
    z=x+8
    NoLev2:? Button z,1,255,0,VarBut?,0,NoLev2?
    Branch x,[noparse][[/noparse]Notaoff5,Notaoff6,Notaoff7,Notaoff8,main]
    end



    it was a laser-based interactive midi instrument I built for the burning
    man arts festival.
    I have a number of boards put together that do multiple switches into
    the midi output.
    (http://www.zenchemical.com/burningman/congruence)



    MIDI output
    Very easy to wire up. Use the Stamp II "serout" command, with baud rate
    number of 12 (which corresponds to the MIDI rate of 31250 baud). You
    need to know something about the format of MIDI commands (look here and
    here). You'll be sending three or four bytes down the line in this sort
    of format:

    SEROUT 15,12,0,[noparse][[/noparse]144,60,80]
    The numbers in the square brackets are a MIDI note-on message
    144 = "This is a note-on, on MIDI channel 1"
    60 = "Middle C"
    80 = "Medium loud"


    MIDI input
    Well, I did once establish that it is possible, but it is extremely
    unreliable. Wiring it up is a little more complicated too, as it
    involves an optoisolator chip and a few other components. The problem is
    that the Stamp, having no interrupt, will miss bytes unless you are
    there at the right moment to catch them with the SERIN command. Then you
    will have to write a MIDI parser to determine what the received bytes
    mean.
    (http://mrogalsky.web.wesleyan.edu/otherthings/voltage-midi/stampMIDI.ht
    ml)





    ' BASIC Stamp II "MIDI LightHarp?"
    ' with 6 photocells, Nat. Semi. 1 of 8 multiplexer CD4051BCN, and
    ' Nat. Semi. ADC0831
    ' based on Parallax A/D application notes
    ' Matt Rogalsky April 1996


    CS con 0 ' chip select is pin 0
    ADCdata con 1 ' ADC data out is pin 1
    CLK con 2 ' ADC clock is pin 2

    MUXa con 3 ' MUX channel select lines
    MUXb con 4
    MUXc con 5

    threshold var byte ' threshold below which a photocell
    threshold = 100 ' will send a MIDI note-on message

    AD0 var byte ' to hold data shifted in from ADC
    AD1 var byte ' for each of 6 photocells
    AD2 var byte
    AD3 var byte
    AD4 var byte
    AD5 var byte

    flag0 var byte ' flags to indicate if photocell was triggered
    flag1 var byte
    flag2 var byte
    flag3 var byte
    flag4 var byte
    flag5 var byte

    key0 var byte ' MIDI note numbers assigned to photocells
    key1 var byte
    key2 var byte
    key3 var byte
    key4 var byte
    key5 var byte

    key0 = 60 ' 60 = middle C
    key1 = 62 ' 62 = D
    key2 = 64 ' 64 = E
    key3 = 65 ' 65 = F
    key4 = 67 ' 67 = G
    key5 = 69 ' 69 = A


    high CS ' deselect ADC to start

    loop: ' MAIN LOOP
    do0:
    gosub select0
    gosub sample0
    do1:
    gosub select1
    gosub sample1
    do2:
    gosub select2
    gosub sample2
    do3:
    gosub select3
    gosub sample3
    do4:
    gosub select4
    gosub sample4
    do5:
    gosub select5
    gosub sample5
    goto loop


    ' **** send MIDI note-ons on MIDI channel 1, using Stamp pin 15 ********
    ' note-on velocity is a constant of 80

    note0:
    serout 15,12,0,[noparse][[/noparse]144,key0,80]
    flag0 = 0
    goto do1

    note1:
    serout 15,12,0,[noparse][[/noparse]144,key1,80]
    flag1 = 0
    goto do2

    note2:
    serout 15,12,0,[noparse][[/noparse]144,key2,80]
    flag2 = 0
    goto do3

    note3:
    serout 15,12,0,[noparse][[/noparse]144,key3,80]
    flag3 = 0
    goto do4

    note4:
    serout 15,12,0,[noparse][[/noparse]144,key4,80]
    flag4 = 0
    goto do5

    note5:
    serout 15,12,0,[noparse][[/noparse]144,key5,80]
    flag5 = 0
    goto do0


    ' ******* sample photocells 0-5, after selecting MUX channel *****

    sample0:
    low CS ' activate ADC
    shiftin ADCdata,CLK,msbpost,[noparse][[/noparse]AD0\9] ' shift in data
    high CS ' deactivate ADC
    if AD0 < threshold and flag0 = 1 then note0
    if AD0 > threshold then flag0high
    return

    sample1:
    low CS
    shiftin ADCdata,CLK,msbpost,[noparse][[/noparse]AD1\9]
    high CS
    if AD1 < threshold and flag1 = 1 then note1
    if AD1 > threshold then flag1high
    return

    sample2:
    low CS
    shiftin ADCdata,CLK,msbpost,[noparse][[/noparse]AD2\9]
    high CS
    if AD2 < threshold and flag2 = 1 then note2
    if AD2 > threshold then flag2high
    return

    sample3:
    low CS
    shiftin ADCdata,CLK,msbpost,[noparse][[/noparse]AD3\9]
    high CS
    if AD3 < threshold and flag3 = 1 then note3
    if AD3 > threshold then flag3high
    return

    sample4:
    low CS
    shiftin ADCdata,CLK,msbpost,[noparse][[/noparse]AD4\9]
    high CS
    if AD4 < threshold and flag4 = 1 then note4
    if AD4 > threshold then flag4high
    return

    sample5:
    low CS
    shiftin ADCdata,CLK,msbpost,[noparse][[/noparse]AD5\9]
    high CS
    if AD5 < threshold and flag5 = 1 then note5
    if AD5 > threshold then flag5high
    return


    ' ************* select channels 0-5 of MUX *************

    select0:
    low MUXa
    low MUXb
    low MUXc
    return

    select1:
    high MUXa
    low MUXb
    low MUXc
    return

    select2:
    low MUXa
    high MUXb
    low MUXc
    return

    select3:
    high MUXa
    high MUXb
    low MUXc
    return

    select4:
    low MUXa
    low MUXb
    high MUXc
    return

    select5:
    high MUXa
    low MUXb
    high MUXc
    return


    ' ****************** set flags high ******************

    flag0high:
    flag0 = 1
    goto do1

    flag1high:
    flag1 = 1
    goto do2

    flag2high:
    flag2 = 1
    goto do3

    flag3high:
    flag3 = 1
    goto do4

    flag4high:
    flag4 = 1
    goto do5

    flag5high:
    flag5 = 1
    goto do0





    ' "green lunchbox" general purpose voltage to midi controller
    ' based on Parallax A/D application notes
    ' Matt Rogalsky December 1997

    ' select 1 of 16 multiplexer (MC14067)
    ' and read data from ADC0831

    ' pins 0,1,2 are used to control the ADC chip
    ' pins 3,4,5,6 are used to select the MUX channel

    ' results are sent out (reduced to 7 bits from 8) as
    ' controllers 20-35 on midi channel 1
    ' latest value is only sent if it is different from the
    ' previous one

    CS con 0 ' chip select is pin 0
    ADCdata con 1 ' ADC data out is pin 1
    CLK con 2 ' ADC clock is pin 2

    AD0 var byte ' to hold data shifted in from ADC
    AD1 var byte ' for each of 16 channels
    AD2 var byte
    AD3 var byte
    AD4 var byte
    AD5 var byte
    AD6 var byte
    AD7 var byte
    AD8 var byte
    AD9 var byte
    AD10 var byte
    AD11 var byte
    AD12 var byte
    AD13 var byte
    AD14 var byte
    AD15 var byte

    pAD0 var byte ' to hold previous data shifted in from ADC
    pAD1 var byte ' for each of 16 channels
    pAD2 var byte
    pAD3 var byte
    pAD4 var byte
    pAD5 var byte
    pAD6 var byte
    pAD7 var byte
    pAD8 var byte
    pAD9 var byte
    pAD10 var byte
    pAD11 var byte
    pAD12 var byte
    pAD13 var byte
    pAD14 var byte
    pAD15 var byte

    high CS ' deselect ADC to start

    loop: ' MAIN LOOP
    do0:
    gosub select0
    gosub sample0
    do1:
    gosub select1
    gosub sample1
    do2:
    gosub select2
    gosub sample2
    do3:
    gosub select3
    gosub sample3
    do4:
    gosub select4
    gosub sample4
    do5:
    gosub select5
    gosub sample5
    do6:
    gosub select6
    gosub sample6
    do7:
    gosub select7
    gosub sample7
    do8:
    gosub select8
    gosub sample8
    do9:
    gosub select9
    gosub sample9
    do10:
    gosub select10
    gosub sample10
    do11:
    gosub select11
    gosub sample11
    do12:
    gosub select12
    gosub sample12
    do13:
    gosub select13
    gosub sample13
    do14:
    gosub select14
    gosub sample14
    do15:
    gosub select15
    gosub sample15
    goto loop


    ' *** send MIDI CC 20 on MIDI channels 1-16, using Stamp pin 15 ***

    cc0:
    serout 15,12,0,[noparse][[/noparse]176,20,AD0]
    pAD0 = AD0
    goto do1

    cc1:
    serout 15,12,0,[noparse][[/noparse]176,21,AD1]
    pAD1 = AD1
    goto do2

    cc2:
    serout 15,12,0,[noparse][[/noparse]176,22,AD2]
    pAD2 = AD2
    goto do3

    cc3:
    serout 15,12,0,[noparse][[/noparse]176,23,AD3]
    pAD3 = AD3
    goto do4

    cc4:
    serout 15,12,0,[noparse][[/noparse]176,24,AD4]
    pAD4 = AD4
    goto do5

    cc5:
    serout 15,12,0,[noparse][[/noparse]176,25,AD5]
    pAD5 = AD5
    goto do6

    cc6:
    serout 15,12,0,[noparse][[/noparse]176,26,AD6]
    pAD6 = AD6
    goto do7

    cc7:
    serout 15,12,0,[noparse][[/noparse]176,27,AD7]
    pAD7 = AD7
    goto do8

    cc8:
    serout 15,12,0,[noparse][[/noparse]176,28,AD8]
    pAD8 = AD8
    goto do9

    cc9:
    serout 15,12,0,[noparse][[/noparse]176,29,AD9]
    pAD9 = AD9
    goto do10

    cc10:
    serout 15,12,0,[noparse][[/noparse]176,30,AD10]
    pAD10 = AD10
    goto do11

    cc11:
    serout 15,12,0,[noparse][[/noparse]176,31,AD11]
    pAD11 = AD11
    goto do12

    cc12:
    serout 15,12,0,[noparse][[/noparse]176,32,AD12]
    pAD12 = AD12
    goto do13

    cc13:
    serout 15,12,0,[noparse][[/noparse]176,33,AD13]
    pAD13 = AD13
    goto do14

    cc14:
    serout 15,12,0,[noparse][[/noparse]176,34,AD14]
    pAD14 = AD14
    goto do15

    cc15:
    serout 15,12,0,[noparse][[/noparse]176,35,AD15]
    pAD15 = AD15
    goto do0


    ' ****** sample photocells 0-15, after selecting MUX channel *****

    sample0:
    low CS ' activate ADC
    shiftin ADCdata,CLK,msbpost,[noparse][[/noparse]AD0\9] ' shift in data
    high CS ' deactivate ADC
    AD0 = AD0 >> 1 ' divide by 2
    if AD0 <> pAD0 then cc0 ' if new value, send as cc
    return

    sample1:
    low CS
    shiftin ADCdata,CLK,msbpost,[noparse][[/noparse]AD1\9]
    high CS
    AD1 = AD1 >> 1
    if AD1 <> pAD1 then cc1
    return

    sample2:
    low CS
    shiftin ADCdata,CLK,msbpost,[noparse][[/noparse]AD2\9]
    high CS
    AD2 = AD2 >> 1
    if AD2 <> pAD2 then cc2
    return

    sample3:
    low CS
    shiftin ADCdata,CLK,msbpost,[noparse][[/noparse]AD3\9]
    high CS
    AD3 = AD3 >> 1
    if AD3 <> pAD3 then cc3
    return

    sample4:
    low CS
    shiftin ADCdata,CLK,msbpost,[noparse][[/noparse]AD4\9]
    high CS
    AD4 = AD4 >> 1
    if AD4 <> pAD4 then cc4
    return

    sample5:
    low CS
    shiftin ADCdata,CLK,msbpost,[noparse][[/noparse]AD5\9]
    high CS
    AD5 = AD5 >> 1
    if AD5 <> pAD5 then cc5
    return

    sample6:
    low CS
    shiftin ADCdata,CLK,msbpost,[noparse][[/noparse]AD6\9]
    high CS
    AD6 = AD6 >> 1
    if AD6 <> pAD6 then cc6
    return

    sample7:
    low CS
    shiftin ADCdata,CLK,msbpost,[noparse][[/noparse]AD7\9]
    high CS
    AD7 = AD7 >> 1
    if AD7 <> pAD7 then cc7
    return

    sample8:
    low CS
    shiftin ADCdata,CLK,msbpost,[noparse][[/noparse]AD8\9]
    high CS
    AD8 = AD8 >> 1
    if AD8 <> pAD8 then cc8
    return

    sample9:
    low CS
    shiftin ADCdata,CLK,msbpost,[noparse][[/noparse]AD9\9]
    high CS
    AD9 = AD9 >> 1
    if AD9 <> pAD9 then cc9
    return

    sample10:
    low CS
    shiftin ADCdata,CLK,msbpost,[noparse][[/noparse]AD10\9]
    high CS
    AD10 = AD10 >> 1
    if AD10 <> pAD10 then cc10
    return

    sample11:
    low CS
    shiftin ADCdata,CLK,msbpost,[noparse][[/noparse]AD11\9]
    high CS
    AD11 = AD11 >> 1
    if AD11 <> pAD11 then cc11
    return

    sample12:
    low CS
    shiftin ADCdata,CLK,msbpost,[noparse][[/noparse]AD12\9]
    high CS
    AD12 = AD12 >> 1
    if AD12 <> pAD12 then cc12
    return

    sample13:
    low CS
    shiftin ADCdata,CLK,msbpost,[noparse][[/noparse]AD13\9]
    high CS
    AD13 = AD13 >> 1
    if AD13 <> pAD13 then cc13
    return

    sample14:
    low CS
    shiftin ADCdata,CLK,msbpost,[noparse][[/noparse]AD14\9]
    high CS
    AD14 = AD14 >> 1
    if AD14 <> pAD14 then cc14
    return

    sample15:
    low CS
    shiftin ADCdata,CLK,msbpost,[noparse][[/noparse]AD15\9]
    high CS
    AD15 = AD15 >> 1
    if AD15 <> pAD15 then cc15
    return


    ' ********** select channels 0-15 of MUX ***********

    select0:
    low 3
    low 4
    low 5
    low 6
    return

    select1:
    high 3
    low 4
    low 5
    low 6
    return

    select2:
    low 3
    high 4
    low 5
    low 6
    return

    select3:
    high 3
    high 4
    low 5
    low 6
    return

    select4:
    low 3
    low 4
    high 5
    low 6
    return

    select5:
    high 3
    low 4
    high 5
    low 6
    return

    select6:
    low 3
    high 4
    high 5
    low 6
    return

    select7:
    high 3
    high 4
    high 5
    low 6
    return

    select8:
    low 3
    low 4
    low 5
    high 6
    return

    select9:
    high 3
    low 4
    low 5
    high 6
    return

    select10:
    low 3
    high 4
    low 5
    high 6
    return

    select11:
    high 3
    high 4
    low 5
    high 6
    return

    select12:
    low 3
    low 4
    high 5
    high 6
    return

    select13:
    high 3
    low 4
    high 5
    high 6
    return

    select14:
    low 3
    high 4
    high 5
    high 6
    return

    select15:
    high 3
    high 4
    high 5
    high 6
    return

    Original Message
    From: i love rooms [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=O9Y5oXln9x7-U0-7UTmvwRR6Hq7FthoUl0iW3HFDpO6zbN1IN1wP7ZQWeH0TqNKPTZwYFz-059Rxmxh1]iloverooms@h...[/url
    Sent: Wednesday, July 10, 2002 12:36 PM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] simple switch to midi


    I am a new user of the stamp; The project that I am taking on is pretty

    simple....All I want to do is send a on/off signal from analog switch to
    a
    midi signal.....
    Can anyone tell me where I could find schematics and code to do this?

    Thanks in advance for any help...

    t
Sign In or Register to comment.