Java: Adding example for MQ3 Gas Sensor

Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
Abhishek Malik 2015-10-23 11:31:56 -07:00
parent 3d8b732158
commit 053cf15495

View File

@ -0,0 +1,58 @@
import upm_gas.Gas;
import upm_gas.MQ2;
import upm_gas.MQ3;
import upm_gas.MQ4;
import upm_gas.MQ5;
import upm_gas.MQ6;
import upm_gas.MQ7;
import upm_gas.MQ8;
import upm_gas.MQ9;
import upm_gas.TP401;
import upm_gas.thresholdContext;
public class GroveMQ3 {
static {
try {
System.loadLibrary("javaupm_gas");
System.loadLibrary("mraajava");
} catch (UnsatisfiedLinkError e) {
System.err.println(
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
e);
System.exit(1);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
//! [Interesting]
// initialize the sensor on A0
MQ3 mq3 = new MQ3(0);
short[] buffer = new short[128];
thresholdContext context = new thresholdContext();
context.setAverageReading(0);
context.setRunningAverage(0);
context.setAveragedOver(2);
int len;
int thres;
while(true){
len = mq3.getSampledWindow((long)2, buffer);
if(len != 0){
thres = mq3.findThreshold(context, 30, buffer);
mq3.printGraph(context, (short)5);
if(thres != 0){
// do something
System.out.println("threshold is crossed");
}
}
}
//! [Interesting]
}
}