Multiple I2C event handlers

Hi all,

So I have my two Arduino Unos connected over I2C. I have no code for this project right now, though I know that the I2C bus works since I've used it before. What I want to do is to set two different event handlers on my Slave, meaning that it does different things based on what it is sent.

To clarify, what I've used before and what everyone seems to use is this within their Slave code:

void setup() {
Wire.begin([i]address[/i]);
Wire.onRecieve(receiveEvent);
}

void receiveEvent(int howManyBytes) {
// Do something
}

What I want is something like this:

void setup() {
Wire.begin();
Wire.onReceive1(receiveEvent1);
Wire.onReceive2(receiveEvent2);
}

void receiveEvent1 (int howMany1) {
// Do something
}

void receiveEvent2 (int howMany2) {
// Do something else
}

The reason this might be helpful is if the Slave has two motors, and one event makes the first one go forward, and the second makes the second motor go forward. (Not what I'll be using it for, but just some context).

Is the same vein, would it be possible to setup two different requestEvents()?

I know that a way around this would be to have one receiveEvent() with statements to do things based on what it received, and with the requestEvent(), just send all the data at once in multiple bytes. But I'm wondering if it's doable with multiple event handlers.

Thanks.

The only issue I can see is that you would need more IIC traffic than you would have if you just passed a variable even if the actions were interdependent... One IIC transmission and and one data byte and a case statement would allow for more flexibility...
Half the IIC time and up to 256 actions or combinations of actions... Still call the same functions with a single IIC transmission. With the benefit of a default condition built in to the code.
The reasoning on my part is that the process is serial as the processor can only do one thing at a time...
While it is a common practice to interleave tasks I'm not aware of anything that has to happen exactly simultaneously.
In my experience a case statement is easier to modify and to debug, should that be necessary.

Doc

What I want to do is to set two different event handlers on my Slave, meaning that it does different things based on what it is sent.

You can't do that. Data arrives. THAT is the event that needs to be handled. In THE handler, you can take different actions based on WHAT was received.