No Description

MPR121Sample.java 723B

12345678910111213141516171819202122232425262728293031323334
  1. public class MPR121Sample {
  2. private static void printButtons(upm_mpr121.MPR121 touch) {
  3. boolean buttonPresed = false;
  4. System.out.print("Buttons pressed: ");
  5. for (int i = 0; i < 12; i++) {
  6. if ((touch.getM_buttonStates() & (1 << i)) != 0) {
  7. System.out.print(i + " ");
  8. buttonPresed = true;
  9. }
  10. }
  11. if (!buttonPresed)
  12. System.out.print("None ");
  13. System.out.println();
  14. }
  15. public static void main(String[] args) throws InterruptedException {
  16. // Instantiate an MPR121 on I2C bus 0
  17. upm_mpr121.MPR121 touch = new upm_mpr121.MPR121(0);
  18. // init according to AN3944 defaults
  19. touch.configAN3944();
  20. while (true) {
  21. touch.readButtons();
  22. printButtons(touch);
  23. Thread.sleep(1000);
  24. }
  25. }
  26. }