/home/pi/NetBeansProjects/EmbeddedApplication1/src/embeddedapplication1/GPIOinTest.java
 1 /*
 2  * To change this license header, choose License Headers in Project Properties.
 3  * To change this template file, choose Tools | Templates
 4  * and open the template in the editor.
 5  */
 6 
 7 package embeddedapplication1;
 8 
 9 import java.lang;
10 /**
11  *
12  * @author Signal Procedures
13  */
14 public class GPIOinTest implements PinListener,AutoCloseable {
15     //Emulator Port Names
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         //Open the LED pin (output)
22         led1 = DeviceManager.open(LED1_ID);
23         
24         // Config file for the button - trigger on a rising edge (from low to high)
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         //Open the BUTTON pin (Input)
32         button1 = DeviceManager.open(config1);
33         //Add this class as a pin listener to the buttons
34         button1.setInputListener(this);
35         //Turn the LED on,then off - this tests the LED
36         led1.setValue(true);
37         try {
38             Thread.sleep(1000);
39         } catch (InterruptedExeption ex){
40     }
41         //Start with the LED off (false)
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         // Simple one button = one LED        
62         try {
63             System.out.println("setting led1");
64             led1.setValue(!led1.getValue()); // Toggle the value of the led
65         } catch (IOException ex) {
66             System.out.println("IOException: " + ex);
67         }
68     }
69 }