1

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
1
  • 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. Commented Mar 9, 2016 at 8:24

1 Answer 1

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.