Created
May 30, 2018 12:48
-
-
Save winhtut/a11db308e9f5fae24872dbb71480dd5e to your computer and use it in GitHub Desktop.
Led On and Off with java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MIDlet-Name: BlinkingLED | |
MIDlet-Version: 1.0 | |
MIDlet-Vendor: PiJava Tutorials | |
MIDlet-1: BlinkingLED,,BlinkingLED | |
MIDlet-Jar-Size: | |
MIDlet-Jar-URL: BlinkingLED.jar |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MIDlet-Name: BlinkingLED | |
MIDlet-Version: 1.0 | |
MIDlet-Vendor: PiJava Tutorials | |
MIDlet-1: BlinkingLED,,BlinkingLED | |
MicroEdition-Configuration: CLDC-1.8 | |
MicroEdition-Profile: MEEP-8.0 | |
MIDlet-Permission-1: jdk.dio.DeviceMgmtPermission "*:*" "open" | |
MIDlet-Permission-2: jdk.dio.gpio.GPIOPinPermission "*:*" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.microedition.midlet.MIDlet; | |
import jdk.dio.gpio.*; | |
import jdk.dio.*; | |
import java.io.*; | |
class BlinkingLED extends MIDlet implements PinListener { | |
private static GPIOPin pin = null; | |
@Override | |
public void startApp() { | |
System.out.println("in startApp method"); | |
try { | |
GPIOPinConfig config = new GPIOPinConfig.Builder() | |
.setControllerNumber(0) | |
.setPinNumber(18) | |
.setDirection(GPIOPinConfig.DIR_OUTPUT_ONLY) | |
.setDriveMode(GPIOPinConfig.MODE_OUTPUT_PUSH_PULL) | |
.setInitValue(false) | |
.build(); | |
pin = DeviceManager.open(GPIOPin.class, config); | |
for (int i = 0; i < 200; i++) { | |
pin.setValue(true); | |
System.out.println("On " + i); | |
Thread.sleep(100); | |
pin.setValue(false); | |
Thread.sleep(900); | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} catch(InterruptedException e) { | |
System.out.println("Thread interrupted: " + e.getMessage()); | |
} finally { | |
try { | |
if (pin != null) { | |
System.out.println("Closing GPIO pin"); | |
pin.close(); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
@Override | |
public void destroyApp(boolean unconditional) { | |
try { | |
if (pin != null) { | |
System.out.println("destroy called, closing GPIO pin"); | |
pin.close(); | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
@Override | |
public void valueChanged(PinEvent event) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment