And you think having done something similar proofes that a different code does not work?
O. M. G.
You are asking for the almost sophisticated way of coding without beeing able to manage coding limiting encoder-values. And without having an idea what variables exactly are.
You seem not to even understand what arrays are.
Arrays are a special kind of variables.
If you would like to put variables into an array this would require pointers to the RAM-locations where these variables values are stored at.
Dealing with pointers is another level. And maybe I am wrong but I got the impression that you should learn more basic things before entering this real advanced stuff.
If you would post a description of what functionality you want to have that goes quite beyond what you have posted so far
Then good suggestions can be made.
As a side-note. User gcjr - most of the time offers - highly sophisticated code with pretty short names which requires either a big amount of knowledge I am not exaggerating or hundreds of jours to learn.
He is a retired professional software-developper that collected knowledge over decades by professional coding. He is able to explain simple things but starts at a pretty high level. Which is - in most cases - way above the head of the thread-openers.
Here is a simple example on how using some good libraries could help make your life and code easier
the code does not do much yet but it sets things up nicely
the rotary encoder is managed and the call to testEncoder() will see if the encoder's value has changed. The underlying encoder function actually reads the encoder's value and checks against bounds and will force the encoder to stay within those bounds. This is where you can take action accordingly, in this sample code I just print the new encoder value.
the button is managed and a call to testSwitch() will see if the button has been pressed and you can take action there accordingly. Here I just print "PRESSED".
I did not know what to do with the 2 LEDs you had, so I got them blinking alternatively in a non blocking way to show the code was alive (remove the blink() function to get rid of that).
Now you can "just" add your menu management code into this. You might benefit from studying state machines to handle the modes, here is a small introduction to the topic: Yet another Finite State Machine introduction
No one get better at playing tennis by playing with beginners.I am learning, yes. I guess that forum is meant to shre for those who want to. Not to compete with who is higher level or not. I am wise enough to navigate trough all your generous shares and do my home work on my side.
I will try to be more precise in my demands instead of posting full codes. Good Idea. Thanks for the hints.
I already did the set up of the encoder with to leds to really know what kind of pluses/detents I got. That said. The knoledge you share will be helpful. Thanks for that!
Okay I will do this in c programming language book. I got to remember the functionning of arrays now. I am watching var per var in the code you sent me and I mannage to figure out each part by changing var names to make it mine Now I will check the beta and gamma stuff... Will get trough it. Thanks for your shares.
Because thoso I understood I put them commented out. The one I kept alive is the one I did not understand. ( *lbl ) that was just for the question post
instead of having individual variables, i imagined that accessing a variable would be by indexing into the array of structs and accessing the .val element.
an enum can be used to assign symbols, TempC to the index values making it easier to use indicies. see pg 39
My comment was because the code you shared would not compile because you were providing more values in the initialisation than you had fieds in the struct.
I see, there is certain variables in my code that were part of different trials but I dit not remove them. The code I posted is definatly too heavy for what it does. With learning suggestions your guys share, I should be able to figure out how to minimize. Thanks again for contribution.
Thanks and for you as well, I will sure get back when solved nice and smooth. good news years eve too!. By the way, I find french words in the code you sent.... just a coincidence?
void encoderSetValue(long newValue) {
// as encoders can have multiple ticks, we need to take into account possibles ticks that have been engaged
long ticks = encoder.read() & 0b11;
encoder.write(newValue << 2 + ticks); // Propably here the trick for Min to Max when CCW
}
bool menuChange(){ //issu de encoderChanged
long newPosition = encoder.read() >> 1; // divide by 4 as the rotary sends 4 ticks per click(chang/ pour 1)
if (newPosition < modeMinValue) {
newPosition = (encoderValue ); //encoderValue au lieu de encoderMinValue ou encoderMaxValue
encoderSetValue(modeMinValue);
} else if (newPosition > modeMaxValue) {
newPosition = modeMinValue;
encoderSetValue(modeMinValue);
}
if (newPosition != encoderValue) {
encoderValue = newPosition;
return true;
}
return false;
}