2018-02-27 12:12:09 -08:00
|
|
|
public class MPR121_Example {
|
2015-10-08 14:30:12 +03:00
|
|
|
|
|
|
|
private static void printButtons(upm_mpr121.MPR121 touch) {
|
2015-10-02 17:31:43 +03:00
|
|
|
boolean buttonPresed = false;
|
2015-10-08 14:30:12 +03:00
|
|
|
|
2015-10-02 17:31:43 +03:00
|
|
|
System.out.print("Buttons pressed: ");
|
|
|
|
for (int i = 0; i < 12; i++) {
|
2015-10-08 14:30:12 +03:00
|
|
|
if ((touch.getM_buttonStates() & (1 << i)) != 0) {
|
|
|
|
System.out.print(i + " ");
|
2015-10-02 17:31:43 +03:00
|
|
|
buttonPresed = true;
|
|
|
|
}
|
|
|
|
}
|
2015-10-08 14:30:12 +03:00
|
|
|
|
|
|
|
if (!buttonPresed)
|
2015-10-02 17:31:43 +03:00
|
|
|
System.out.print("None ");
|
2015-10-08 14:30:12 +03:00
|
|
|
|
|
|
|
System.out.println();
|
2015-10-02 17:31:43 +03:00
|
|
|
}
|
2015-10-08 14:30:12 +03:00
|
|
|
|
2015-10-02 17:31:43 +03:00
|
|
|
public static void main(String[] args) throws InterruptedException {
|
|
|
|
// Instantiate an MPR121 on I2C bus 0
|
|
|
|
upm_mpr121.MPR121 touch = new upm_mpr121.MPR121(0);
|
2015-10-08 14:30:12 +03:00
|
|
|
|
|
|
|
// init according to AN3944 defaults
|
2015-10-02 17:31:43 +03:00
|
|
|
touch.configAN3944();
|
2015-10-08 14:30:12 +03:00
|
|
|
|
2015-10-02 17:31:43 +03:00
|
|
|
while (true) {
|
|
|
|
touch.readButtons();
|
|
|
|
printButtons(touch);
|
|
|
|
Thread.sleep(1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|