Last active
July 4, 2016 07:14
-
-
Save tullo-x86/34ad95288c5f2dea8773f3d7cc627add to your computer and use it in GitHub Desktop.
How to make MPR121 play with FastLED
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Adafruit_MPR121 _cap; | |
uint16_t _currButtonState; | |
uint16_t _lastButtonState; | |
bool isPressed(int button) { | |
uint16_t bitmask = 1 << button; | |
return !(_lastButtonState & bitmask) && (_currButtonState & bitmask); | |
} | |
void setup() { // or the top of `int main()` -- however you're writing it | |
_cap.begin(0x5A); // I left the address pins open, so it's 0x5A | |
FastLED.addLeds<blahblah>(blah); | |
// etc | |
} | |
void loop() { // or the infinite loop in `int main()` -- again, however you're writing it | |
_lastButtonState = _currButtonState; | |
_currButtonState = _cap.touched(); | |
if (isPressed(2)) { | |
// React | |
} | |
else if (isPressed(0)) { | |
// React differently | |
} | |
// Draw on the LEDs or something | |
FastLED.show(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment