Hello,
i am very new in Arduino, but have some expierience in C#.
So i have my Arduino Mega connected and running. I need them to run Encoders.
For that i have includet this lib: Rotary Lib
It runs good so far.
Bevore the setup funktion i have created my rotary object:
Rotary r_nav1_inner = Rotary(2, 3);
Then in the Setup function i start the Encorder:
r_nav1_inner.begin(true);
in the loop i call the funtion for the encoder:
process_nav1_inner_enc();
This is the funktion:
void process_nav1_inner_enc()
{
unsigned char result = r_nav1_inner.process();
if (result) {
Serial.println("process_nav1_inner_enc");
Serial.println(result);
client.println("Arn.Resp:13=0");
switch (result)
{
case 16:
client.println("Arn.Resp:13=1");
break;
case 32:
client.println("Arn.Resp:13=-1");
break;
}
}
}
But now i want to optimize the code a little bit and process all encoders in only one funktion.
For that i have changed this very little funktion to:
void process_encoders(Rotary r, String sv)
{
unsigned char result = r.process();
if (result) {
Serial.println("process_encoders");
Serial.println(result);
client.println("Arn.Resp:" + sv + "=0");
switch (result)
{
case 16:
client.println("Arn.Resp:" + sv + "=1");
break;
case 32:
client.println("Arn.Resp:" + sv + "=-1");
break;
}
}
}
For that i changed the call for the funktion to this:
process_encoders(r_nav1_inner, sv_nav1_enc_inner);
But this dosent work.
But when i change the line
unsigned char result = r.process();
back to
unsigned char result = r_nav1_inner.process();
It works again.
I dont understand why?
In Cä i do that every time like this.
But in Arduino it seams not to work.
Can anyone give me a tip what i a doing wrong here ?
Thanks
Matthias