[Logo] TCC discussion forum
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Top Downloads] Top Downloads   [Groups] Back to home page 
[Register] Register /  [Login] Login 


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.

IoAbstraction - dual Encoder RSS feed
Forum Index » tcMenu Arduinio library
Author Message
Andre


Joined: Jul 15, 2019
Messages: 15
Offline
Hello Dave,

here I´m trying to get two Encoders working.

What do you mean with slot?:
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.

Kind regards
Andre
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.

You’d normally create additional encoders manually:

HardwareRotaryEncoder* secondEncoder = new HardwareRotaryEncoder(secondEncoderAPin, secondEncoderBPin, onSecondEncoderChange);
switches.setEncoder(1, secondEncoder);

Andre


Joined: Jul 15, 2019
Messages: 15
Offline
Sorry to be so stupid,

#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();  
}


What does I don´t understand?
Andre


Joined: Jul 15, 2019
Messages: 15
Offline
Ok now I got it.
I had to setup both Encoders manually.

void setup() {
  Serial.begin(115200);
  switches.initialise(ioUsingArduino(), true);
  
  switches.addSwitch(encVolumeClickPin, onVolumeEncClicked);
  switches.addSwitch(encMenuClickPin, onMenuEncClicked);
  switches.addSwitch(repeatButtonPin, onRepeatButtonClicked, 25);
  
  HardwareRotaryEncoder* VolumeEnc =new HardwareRotaryEncoder (encVolumeAPin, encVolumeBPin, onVolumeEncChange);
  switches.setEncoder(0,VolumeEnc);
  switches.changeEncoderPrecision(0, maxEncVolume,1);
    
  HardwareRotaryEncoder* MenuEnc =new HardwareRotaryEncoder (encMenuAPin, encMeunBPin, onMenuEncChange); 
  switches.setEncoder(1,MenuEnc);
  switches.changeEncoderPrecision(1, maxEncMenu, 1);
  
}


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?


Thank you Dave!
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
Please take a look at this new page, which describes using more than one encoder in detail.

Be aware that using more than one rotary encoder is an advanced library feature and needs a little more background reading.

https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/tcmenu-plugins/encoder-switches-input-plugin/
 
Forum Index » tcMenu Arduinio library
Go to:   
Mobile view
Powered by JForum 2.7.0 © 2020 JForum Team • Maintained by Andowson Chang and Ulf Dittmer

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.

Our privacy policy applies to all pages on our site

Should you need further guidance on how to proceed: External link for information about cookie management.