I assume your keypad is transmitting ASCII codes for the keys, that would work for key down, but not for key release, and I hear you also want to transmit three channels of accelerometer data.
With just keydown, one byte can tell everything, I suggest these steps:
- create a "script/script2" object. This one only provides 2 inlets/outlets of a fixed type, we need to modify this...
- on the object popup-menu, select "embed", now you can customize its in- and outlets
- the "script/script2" object became a "patch/object". This is a special object, it means the definition of the object is contained in the patch, not in a library. It will have a 2nd edit button. 1st one is for editing the "script", the 2nd one is to edit the object.
- push the 2nd edit button of the object, to add in- and outlets relevant to the keypad. I guess 16 outputs of the "bool32.pulse" type if you're not interested in key-up events.
- in the object editor tab "local data", you need to add variables corresponding to the in- and outlets, like already present for in1, in2, out1, out2.
- in the object editor tab "k-rate code", you need to add assignments similar to what is already present for in1, in2, out1, out2.
- now first check if the patch with this object skeleton still compiles and runs.
- in the script (accessed via the script - edit button on the object) you'll need to enter something like
:
void setup(void) {
}
void loop(void) {
// read all pending bytes
while(!sdGetWouldBlock(&SD2)) {
char x = sdGet(&SD2);
switch(x) {
case '0': out0 = 1; break;
case '1': out1 = 1; break;
case '2': out2 = 1; break;
// add other cases here
default: LogTextMessage("unhandled: 0x%X",x);
}
}
chThdSleepMilliseconds(3);
out0 = 0;
out1 = 0;
out2 = 0;
}
But if you also want to combine three channels of accelerometer data, you need some sort of protocol to tell keycodes apart from accelerometer data. I don't have time here to write a book chapter about best practices in protocol encoding/decoding, I don't know how familiar you are with Arduino, please be more specific in questions. It would be helpful if you could provide code that would decode the protocol on Arduino. If my example code does not make any sense, please understand I do prefer spending time on development rather than teaching programming basics. Still completely fine to be discussed here, but I'm not likely to engage in such discussion.
Entering code can be as easy as clicking "edit" on a "script/script2" object. Did you do "sync libraries" in 1.0.10, and found the help patch associated with the "gpio/serial/config" object?