upm/examples/java/MPR121Sample.java
Stefan Andritoiu 9bf184129e java: removed loadLibrary preamble from examples
Signed-off-by: Stefan Andritoiu <stefan.andritoiu@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2015-12-04 17:41:26 -08:00

34 lines
723 B
Java

public class MPR121Sample {
private static void printButtons(upm_mpr121.MPR121 touch) {
boolean buttonPresed = false;
System.out.print("Buttons pressed: ");
for (int i = 0; i < 12; i++) {
if ((touch.getM_buttonStates() & (1 << i)) != 0) {
System.out.print(i + " ");
buttonPresed = true;
}
}
if (!buttonPresed)
System.out.print("None ");
System.out.println();
}
public static void main(String[] args) throws InterruptedException {
// Instantiate an MPR121 on I2C bus 0
upm_mpr121.MPR121 touch = new upm_mpr121.MPR121(0);
// init according to AN3944 defaults
touch.configAN3944();
while (true) {
touch.readButtons();
printButtons(touch);
Thread.sleep(1000);
}
}
}