1 public class MPR121Sample { 2 3 static { 4 try { 5 System.loadLibrary("javaupm_mpr121"); 6 } catch (UnsatisfiedLinkError e) { 7 System.err.println("error in loading native library"); 8 System.exit(-1); 9 } 10 } 11 printButtons(upm_mpr121.MPR121 touch)12 private static void printButtons(upm_mpr121.MPR121 touch) { 13 boolean buttonPresed = false; 14 15 System.out.print("Buttons pressed: "); 16 for (int i = 0; i < 12; i++) { 17 if ((touch.getM_buttonStates() & (1 << i)) != 0) { 18 System.out.print(i + " "); 19 buttonPresed = true; 20 } 21 } 22 23 if (!buttonPresed) 24 System.out.print("None "); 25 26 System.out.println(); 27 } 28 main(String[] args)29 public static void main(String[] args) throws InterruptedException { 30 // Instantiate an MPR121 on I2C bus 0 31 upm_mpr121.MPR121 touch = new upm_mpr121.MPR121(0); 32 33 // init according to AN3944 defaults 34 touch.configAN3944(); 35 36 while (true) { 37 touch.readButtons(); 38 printButtons(touch); 39 Thread.sleep(1000); 40 } 41 } 42 43 }