Register / Login | Desktop view |
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);
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* secondEncoder = new HardwareRotaryEncoder(secondEncoderAPin, secondEncoderBPin, onSecondEncoderChange);
switches.setEncoder(1, secondEncoder);
#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();
}
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);
}