disc1
-RT * ln(k)
What's going on here. First off, look at the new setup and loop functions. It's what we made earlier with the array, and everything is right there with it. All of the Rotary Encoder stuff has been moved away from the main program except for the calls to attachVariable() and detachVariable().
Look at all of those function calls. There's the dot operator. (and a weird expression for the index of number[]. How do we know it's never greater than 2?)
knob.attachVariable(number[ total%3 ]);
knob is the name of our object. It is of class type QuickRotaryEncoder.
The class is defined right at the top after the includes and defines. It starts with the keyword class, then the name of the class, QuickRotaryEncoder, then a brace {.
Then we have all of our member variables. Some are public, some are private. Public variables and functions are available to everyone. These are the one's we want the user to use. The private variables and functions are to be used only within the class. You can't call them in the main program. This is all the stuff we don't want the user messing with because it will mess up the program.
After the main program you find all of the member functions. Notice that we have added the scope operator :: to all of the ones that belong to the class, but not to printMyNumbers() because is belongs to the example program.
void QuickRotaryEncoder::attachVariable(int& _var)
{
attached_val = &(_var);
attachFunction();
}
Nothing else has had to change about our functions. We just made sure they had the scope of the class we made so they will have access to the member variables.
In the class definition, we also made a couple of member functions static. Namely, doEncoderA() for the reasons discussed above, and setupPins(byte, byte) for safety reasons since it only deals with static member variables.
We have to make all of the member variables used by the static doEncoderA() static. So that's all the pin / port / bit_mask business and attached_val. There's only one copy of attached_val no matter how many QuickRotaryEncoder objects you try to make. They all have to share the same one. So in reality, we are going to be limited to a single encoder. (Although we can sort-of fix this later by adding the other interrupt to the class to expand it to two)
Remember I said the static members had to be initialized at some point out in program space? Well that's right in between the class definition and the set-up part. Note the syntax, but I'm not going to go into it because you shouldn't have to do that again for anything.
:fun4:
Look at all of those function calls. There's the dot operator. (and a weird expression for the index of number[]. How do we know it's never greater than 2?)
knob.attachVariable(number[ total%3 ]);
knob is the name of our object. It is of class type QuickRotaryEncoder.
The class is defined right at the top after the includes and defines. It starts with the keyword class, then the name of the class, QuickRotaryEncoder, then a brace {.
Then we have all of our member variables. Some are public, some are private. Public variables and functions are available to everyone. These are the one's we want the user to use. The private variables and functions are to be used only within the class. You can't call them in the main program. This is all the stuff we don't want the user messing with because it will mess up the program.
After the main program you find all of the member functions. Notice that we have added the scope operator :: to all of the ones that belong to the class, but not to printMyNumbers() because is belongs to the example program.
void QuickRotaryEncoder::attachVariable(int& _var)
{
attached_val = &(_var);
attachFunction();
}
Nothing else has had to change about our functions. We just made sure they had the scope of the class we made so they will have access to the member variables.
In the class definition, we also made a couple of member functions static. Namely, doEncoderA() for the reasons discussed above, and setupPins(byte, byte) for safety reasons since it only deals with static member variables.
We have to make all of the member variables used by the static doEncoderA() static. So that's all the pin / port / bit_mask business and attached_val. There's only one copy of attached_val no matter how many QuickRotaryEncoder objects you try to make. They all have to share the same one. So in reality, we are going to be limited to a single encoder. (Although we can sort-of fix this later by adding the other interrupt to the class to expand it to two)
Remember I said the static members had to be initialized at some point out in program space? Well that's right in between the class definition and the set-up part. Note the syntax, but I'm not going to go into it because you shouldn't have to do that again for anything.
:fun4: