Added example for multiple instanciation.
This commit is contained in:
		
							parent
							
								
									a63afb0868
								
							
						
					
					
						commit
						d2c54c2d18
					
				|  | @ -0,0 +1,45 @@ | |||
| #include <SoftwareSerial.h> | ||||
| #include <MIDI.h> | ||||
| 
 | ||||
| // This example shows how to create two instances of the library to create a merger.
 | ||||
| // There are two MIDI couples of IO, A and B, each using thru and merging with the
 | ||||
| // input from the other node. The result is the following:
 | ||||
| // A out = A in + B in
 | ||||
| // B out = B in + A in
 | ||||
| 
 | ||||
| SoftwareSerial softSerial(2,3); | ||||
| 
 | ||||
| MIDI_CREATE_INSTANCE(HardwareSerial, Serial,     midiA);  | ||||
| MIDI_CREATE_INSTANCE(SoftwareSerial, softSerial, midiB); | ||||
| 
 | ||||
| void setup() | ||||
| { | ||||
|   // Initiate MIDI communications, listen to all channels
 | ||||
|   midiA.begin(MIDI_CHANNEL_OMNI); | ||||
|   midiB.begin(MIDI_CHANNEL_OMNI); | ||||
| } | ||||
| 
 | ||||
| void loop() | ||||
| { | ||||
|     if (midiA.read()) | ||||
|     { | ||||
|         // Thru on A has already pushed the input message to out A.
 | ||||
|         // Forward the message to out B as well.
 | ||||
|         midiB.send(midiA.getType(), | ||||
|                    midiA.getData1(), | ||||
|                    midiA.getData2(), | ||||
|                    midiA.getChannel()); | ||||
|     } | ||||
|      | ||||
|     if (midiB.read()) | ||||
|     { | ||||
|         // Thru on B has already pushed the input message to out B.
 | ||||
|         // Forward the message to out A as well.
 | ||||
|         midiA.send(midiB.getType(), | ||||
|                    midiB.getData1(), | ||||
|                    midiB.getData2(), | ||||
|                    midiB.getChannel()); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
		Loading…
	
		Reference in New Issue
	
	 Francois Best
						Francois Best