at first :: this is amazing :: great project :: well done :: great potential :: !! ::
i need some help ::
want to build a midi controller , have an encoder ky-040 board , want to detect the direction of the rotation and send when specific CC messages …
i have done so far :: midi is going well thru over USB port, edited some of the code in controlchange lib by awgrover ( you forgot to name the input_CC/input_Val/input_Ch correctly so the compiler gone wild at line 37-39 - inside the node) , but as for nice soft i could do it by myself
i dont need to count , i just need to send a CCxx when clockwise or CCyy when counterclockwise
struct State {
// We need store the last state permanently, so put it in State
bool lastState;
};
{{ GENERATED_CODE }}
void evaluate(Context ctx) {
auto state = getState(ctx);
// Read port numbers from XOD inputs labeled PA and PB (you should create them)
auto portA = (uint8_t)getValue<input_PA>(ctx);
auto portB = (uint8_t)getValue<input_PB>(ctx);
auto currentState = digitalRead(portA);
if (currentState != state->lastState) {
if (digitalRead(portB) != state)
emitValue<output_CW>(ctx, 1); // clockwise pulse on XOD pin CW
else
emitValue<output_CCW>(ctx, 1); // counterclockwise pulse on XOD pin CCW
}
state->lastState = currentState;
}
I wrote this blindly, without any checks, but I hope you get the idea on how to transofrm the code.
1 the compiler makes input_input_xy so all the names has to be changed in arduino ide ( no problem )
2 if i get it compiled to a state : no undeclared vars any more i get a warning about compare pointer to number problem:: if (currentState != state->lastState) {
but it let upload , but not working … any input from encoder is not working…
im not the code type any more … it look to me like the lastState var is not set once in the code ?? only defined.
Hello! It’s very hard to complete a node for hardware you don’t have. I would be able to try implement encoder support as soon as I’ll get one. Not sure when it’d happen. So, if anyone has similar one already, it would be great if you’d take a look.
fisrt of all I have to say that XOD is wonderfull and I am very thankfull for such an easy to use tool.
microsoundfiled: I have rocegnized, that nkrkv has prepared the C++ code for numeral inputs - numbers of pins, so the issue is with the usage of boolean input nodes. However I was not able to make the script functional. So I have prepared litle bit modificated script for countig encoder pulses. This works quite well. Now its up to you to decide which direction is the schaft moving.
struct State {
bool lastState;
};
{{ GENERATED_CODE }}
void evaluate(Context ctx) {
auto state = getState(ctx);
auto CLK = (bool)getValue<input_CLK>(ctx); // boolean digital inputs
auto DT = (bool)getValue<input_DT>(ctx);
Number count = getValue<output_OUT>(ctx); // count declaration
auto currentState = CLK; // actual state store
if ((state->lastState== false) && (currentState == true)) {
if (DT == false)
count+=1; // clockwise increment
else
count-=1; // counterclockwise decrement
}
state->lastState = currentState;
emitValue<output_OUT>(ctx,count);
Well, it seems to me, that I have published the library in wrong way. Please be patient, I am a newbie to this. I will try to add next version to the library corectly asap . I will let you know.
One year later and I’ve found your library to be very helpful. It works perfectly when debugging (counts increase/decrease as expected, no bouncing; CW/CCW shift true/false accurately; button push = count reset).
However, when I attach an LCD (16x2 i2c) in place of the watch nodes, the output to the screen is not accurate at all (count or direction), button pushes are fine and reset the count to zero.
Would you have any insight on why there would be a difference and how to correct for it?
If LCD display is sometimes correct, that implies it is wired up correctly. Is it just not updating all the time so it lags behind? I can’t think of any other reason it would be working differently than watch nodes…
Can you share your program? Maybe that would reveal something.