upm/examples/java/GroveQTouch_Example.java
Mihai Tudor Panu 89d5de43e0 license: update to SPDX style license text throughout
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2020-03-05 15:13:36 -08:00

57 lines
1.3 KiB
Java

/*
* Author: Abhishek Malik <abhishek.malik@intel.com>
* Copyright (c) 2015 Intel Corporation.
*
* This program and the accompanying materials are made available under the
* terms of the The MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
*/
import upm_at42qt1070.AT42QT1070;
public class GroveQTouch_Example {
public static void main(String[] args) {
// TODO Auto-generated method stub
// Instantiating the Q Touch sensor on the I2C bus 0
AT42QT1070 touch = new AT42QT1070(0, (short) 0x1b);
short pressedButtons;
// ! [Interesting]
while(true){
touch.updateState();
printButtons(touch.getButtons());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.println(e.toString());
}
}
// ! [Interesting]
}
/**
* This function prints out the button numbers from 0 through 6
* @param buttonNumber
*/
public static void printButtons(int buttonNumber){
boolean buttonPressed = false;
System.out.print("Button Pressed: ");
for(int i=0;i<7;i++){
if((buttonNumber & (1<<i)) != 0){
System.out.println(i+" ");
buttonPressed = true;
}
}
if(!buttonPressed){
System.out.println("None ");
}
}
}