belangeo / pyo-bela

Template to create a pyo project on the bela platform
GNU Lesser General Public License v3.0
12 stars 4 forks source link

Trigger (digital) inputs? #5

Open csik opened 5 years ago

csik commented 5 years ago

I'm new to pyo and the pyo-bela implementation, but I don't see any functionality for digital io (triggers) in the current pyo-bela code. If I'm not missing anything, I'm wondering if there is any plan to add this? I'm currently learning pyo to use with a Bela pepper.

It seems that a seamless approach would be to associate a digital input with a Trig, so that a rising voltage is treated just as any other output from Trig.play() would be. Similarly a trigger output might be able to fire on an event as would a Trig or Metro. I guess I can imagine how these could be hacked using existing functions, but also that this would be more cpu intensive. I guess this implementation would mean using pin interrupts under the BBB hood, unless there's an event loop already polling for this constantly.

Am I missing something altogether? Thanks.

csik commented 4 years ago

This code in render.cpp seems to be able to alert a Sig() object to a changing pin: bool pin12 = 0;

if (digitalRead(context, 0, 12) != pin12){
pin12 = !pin12;
pyo.value("pin_12", pin12);
}

This is a quick way of getting pin values into the python environment, but I suspect a proper implementation would: 1) allow for in-python setting of pin directions (is it input or output?) and, for outputs, set them. This is currently a C->python direction, and we'd need python->C to set pins.