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;
}

}

  • 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 Mar 9 '16 at 8:24
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.