1

I am using a mcp23017 to read button presses for my joystick project and am using the internal pullup to minimize complications. Is there a way to invert all the bits in the uint16_t so i can send the values as normally off?

I'm using this Adafruit library.

And the reading code: uint16_t buttons = mcp.readGPIOAB();

3

The inversion operator in C++ is ~.

Serial.print(buttons, BIN);
Serial.print(~buttons, BIN);
2
  • Amazing dude thanks!!! I added a ~ in front of mcp.digitalReadGPIOAB(); and that has done the trick.
    – user862
    Mar 29 '14 at 21:42
  • 1
    Welcome to Arduino! You can click the "accept" button (the green checkmark by the answer) to mark that this solution worked. Thanks! :) Mar 29 '14 at 22:37

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.