This forum is read only and new users cannot register, please ask all new questions either using GitHub discussions, or in Arduino forum tagging @davetcc.
part from SwitchInput.h
/**
* Use this version of changeEncoderPrecision if you are working with more than one rotary encoder.
* This is helper function that calls the rotary encoders change precision function. It changes the
* maximum value that can be represented and also the current value of the encoder.
* @param slot the index of the desired encoder, zero based <<<<----- What does it mean, what kind of variable or Parameter should kicked in?
* @param precision the maximum value to be set
* @param currentValue the current value to be set.
*/
void changeEncoderPrecision(uint8_t slot, uint16_t precision, uint16_t currentValue);
Here the Setup:
void setup() {
Serial.begin(115200);
// First we set up the switches library, giving it the task manager and tell it to use arduino pins
// We could also of chosen IO through an i2c device that supports interrupts.
// If you want to use PULL DOWN instead of PULL UP logic, change the true to false below.
switches.initialise(ioUsingArduino(), true);
// now we add the switches, we dont want the spinwheel button to repeat, so leave off the last parameter
// which is the repeat interval (millis / 20 basically) Repeat button does repeat as we can see.
switches.addSwitch(encVolumeClickPin, onVolumeEncClicked);
switches.addSwitch(encMenuClickPin, onMenuEncClicked);
switches.addSwitch(repeatButtonPin, onRepeatButtonClicked, 25);
// now we set up the rotary encoder, first we give the A pin and the B pin.
// we give the encoder a max value of 128, always minumum of 0.
setupRotaryEncoderWithInterrupt(encVolumeAPin, encVolumeBPin, onVolumeEncChange);
switches.changeEncoderPrecision(0, maxEncVolume,1);
setupRotaryEncoderWithInterrupt(encMenuAPin, encMeunBPin, onMenuEncChange);
switches.changeEncoderPrecision(1, maxEncMenu, 1);
}
I´ve tried a lot of different values for the "slot-param", but only when both values are equal the last encoder (onMenuEncChange) is working.
davetcc Joined: Jan 19, 2019 Messages: 686 Offline
Hi there,
Inside switches there is an array with four slots in it, each one can hold an encoder. TcMenu when using the setup methods always picks the first slot which is 0. To use a second one don’t use the TcMenu setup function. Instead take a look at this example of setting up a second encoder; where you’d basically use slot 1 for the volume encoder. I imagine you’d set the range to be that of maximum volume and call the volume menu setCurrentValue method on every notification from the encoder.
#include<IoAbstraction.h>
// The pin onto which we connected the rotary encoders switch
const int encVolumeClickPin = 12;
const int encMenuClickPin = 0;
// The pin onto which we connected the repeat button switch
const int repeatButtonPin = 25;
// The two pins where we connected the A and B pins of the encoder. I recomend you dont change these
// as the pin must support interrupts.
const int encVolumeAPin = 11;
const int encVolumeBPin = 10;
/////
const int encMenuAPin = 2;
const int encMeunBPin = 1;
// the maximum (0 based) value that we want the encoder to represent.
const int maxEncMenu = 128;
const int maxEncVolume = 255;
//
// When the spinwheel is clicked, this function will be run as we registered it as a callback
//
void onVolumeEncClicked(uint8_t pin, bool heldDown) {
Serial.print("Volume pressed ");
Serial.println(heldDown ? "Held" : "Pressed");
}
void onMenuEncClicked(uint8_t pin, bool heldDown) {
Serial.print("Menu pressed ");
Serial.println(heldDown ? "Held" : "Pressed");
}
//
// When the repeat button is pressed, this function will be repeatedly called. It's also a callback
//
void onRepeatButtonClicked(uint8_t pin, bool heldDown) {
Serial.println("Repeat button pressed");
}
//
// Each time the encoder value changes, this function runs, as we registered it as a callback
//
void onVolumeEncChange(int VolEnc) {
Serial.print("Volume Encoder change ");
Serial.println(VolEnc);
}
void onMenuEncChange(int MenuEnc) {
Serial.print("Menu Encoder change ");
Serial.println(MenuEnc);
}
void setup() {
Serial.begin(115200);
// First we set up the switches library, giving it the task manager and tell it to use arduino pins
// We could also of chosen IO through an i2c device that supports interrupts.
// If you want to use PULL DOWN instead of PULL UP logic, change the true to false below.
switches.initialise(ioUsingArduino(), true);
// now we add the switches, we dont want the spinwheel button to repeat, so leave off the last parameter
// which is the repeat interval (millis / 20 basically) Repeat button does repeat as we can see.
switches.addSwitch(encVolumeClickPin, onVolumeEncClicked);
switches.addSwitch(encMenuClickPin, onMenuEncClicked);
switches.addSwitch(repeatButtonPin, onRepeatButtonClicked, 25);
// now we set up the rotary encoder, first we give the A pin and the B pin.
// we give the encoder a max value of 128, always minumum of 0.
setupRotaryEncoderWithInterrupt(encVolumeAPin, encVolumeBPin, onVolumeEncChange);
switches.changeEncoderPrecision(0, maxEncVolume,1);
//setupRotaryEncoderWithInterrupt(encMenuAPin, encMeunBPin, onMenuEncChange);
switches.changeEncoderPrecision(1, maxEncMenu, 1);
HardwareRotaryEncoder* MenuEnc =new HardwareRotaryEncoder (encMenuAPin, encMeunBPin, onMenuEncChange);
switches.setEncoder(1,MenuEnc);
}
void loop() {
taskManager.runLoop();
}
now I have the challenge to put the two Encoders in the tcMenu Sketch. I guess just to configure the second Encoder will be fine, because the first one is already implemented in tcMenu?
This site uses cookies to analyse traffic, serve ads by Google AdSense (non-personalized in EEA/UK),
and to record consent. We also embed Twitter, Youtube and Disqus content on some pages, these companies
have their own privacy policies.