I am still new to Aduino and I am trying to use a library's example sketch but I don't understand the following part of the code. I want to trigger an led when the "Pressed" condition is fulfilled. Pardon my ignorance.
if (b != ClickEncoder::Open) {
Serial.print("Button: ");
#define VERBOSECASE(label) case label: Serial.println(#label); break;
switch (b) {
VERBOSECASE(ClickEncoder::Pressed);
VERBOSECASE(ClickEncoder::Held)
VERBOSECASE(ClickEncoder::Released)
VERBOSECASE(ClickEncoder::Clicked)
case ClickEncoder::DoubleClicked:
Serial.println("ClickEncoder::DoubleClicked");
encoder->setAccelerationEnabled(!encoder->getAccelerationEnabled());
Serial.print(" Acceleration is ");
Serial.println((encoder->getAccelerationEnabled()) ? "enabled" : "disabled");
setMode = true;
value = 0;
break;
}
}
asked Mar 9, 2016 at 6:46
-
I'm no expert either, but I think this is just Displaying the status of the button out to the Serial port, whether it's been Pressed, Held, Released etc.Lefty– Lefty03/09/2016 08:24:37Commented Mar 9, 2016 at 8:24
1 Answer 1
You will have to explicitely expand the case ClickEncoder::Pressed
. So instead of
VERBOSECASE(ClickEncoder::Pressed);
you should write something like
case ClickEncoder::Pressed:
Serial.println("ClickEncoder::Pressed");
digitalWrite(ledpin, HIGH);
break;
Of course then you'll have to turn it off then, but.. Well, that's another problem
answered Mar 9, 2016 at 9:52
lang-cpp