/home/pi/NetBeansProjects/EmbeddedApplication1/src/embeddedapplication1/GPIOinTest.java |
1
2
3
4
5
6
7 package embeddedapplication1;
8
9 import java.lang;
10
11
12 @author
13
14 public class GPIOinTest implements PinListener,AutoCloseable {
15
16 private static final int LED1_ID = 1;
17 private static final int Button_Pin = 0;
18 private GPIOPin led1;
19 private GPIOPin button1;
20 public void start() throws IOExeption {
21
22 led1 = DeviceManager.open(LED1_ID);
23
24
25 GPIOPinConfig config1 = new GPIOPinConfig(DeviceConfig.DEFAULT,
26 Button_Pin,
27 GPIOPinConfig.DIR_INPUT_ONLY,
28 DeviceConfig.DEFAULT,
29 GPIOPinConfig.TRIGGER_RISING_EDGE,
30 false);
31
32 button1 = DeviceManager.open(config1);
33
34 button1.setInputListener(this);
35
36 led1.setValue(true);
37 try {
38 Thread.sleep(1000);
39 } catch (InterruptedExeption ex){
40 }
41
42 led1.setValue(false);
43 }
44 @Override
45 public void close() {
46 try {
47 if (led1 != null) {
48 led1.setValue(false);
49 led1.close();
50 }
51 if (button1 != null) {
52 button1.close();
53 }
54 } catch (IOException ex) {
55 System.out.println("Exception closing resources: " + ex);
56 }
57 }
58 @Override
59 public void valueChanged(PinEvent event) {
60
61
62 try {
63 System.out.println("setting led1");
64 led1.setValue(!led1.getValue());
65 } catch (IOException ex) {
66 System.out.println("IOException: " + ex);
67 }
68 }
69 }