adafruit / Adafruit_Trellis_Library

Arduino library for controlling Adafruit Trellis
45 stars 24 forks source link

Bitwise instead of logical and in justPressed and justReleased function #4

Closed tdicola closed 10 years ago

tdicola commented 10 years ago

I'm looking at porting the Trellis library to python so it can run on the BBB or Raspi and noticed this code:

boolean Adafruit_Trellis::justPressed(uint8_t k) {
  return (isKeyPressed(k) & !wasKeyPressed(k));
}
boolean Adafruit_Trellis::justReleased(uint8_t k) {
  return (!isKeyPressed(k) & wasKeyPressed(k));
}

I think the bitwise and (single &) is a bug, shouldn't it be a logical and (&&) to return true if the key is pressed and was or was not previously pressed?

edit: Actually I guess it's fine the way it is since the bitwise and should have the same effect as the logical and here.

ladyada commented 10 years ago

Either will work in this case :) closing this, but if you're feeling up to it, you can push a change.