2016年9月26日 | Leave a comment 问题: JavaME embbed blink demo 解决: 代码 https://github.com/giant35/jme2 使用ubuntu 64bit + netbeans 8.1 + jmesdk8.3 + raspberry pi 3 b+ + raspbian 简介: 刷好 raspbian 后,ssh pi@raspberrypi 密码 respberry raspberrypi 安装 oracle-jmee-8-3-rr-raspberrypi-linux-bin raspberrypi 运行 jmee/bin/runuser.sh netbeans 创建javame embbed 项目,代码如下: package jme2; import javax.microedition.midlet.MIDlet; import jdk.dio.DeviceManager; import jdk.dio.gpio.GPIOPin; import jdk.dio.gpio.GPIOPinConfig; public class Jme2 extends MIDlet { @Override public void startApp() { try { System.out.println("startApp"); //not ok GPIOPin led=DeviceManager.open(3); GPIOPinConfig cfg=new GPIOPinConfig.Builder().setPinNumber(3).setDirection(GPIOPinConfig.DIR_OUTPUT_ONLY).build(); final GPIOPin led=DeviceManager.open(cfg); do{ Thread.sleep(1000); led.setValue(!led.getValue()); System.out.println(" value :"+led.getValue()); }while(true); } catch (Exception ex) { ex.printStackTrace(); } } @Override public void destroyApp(boolean unconditional) { } } 12345678910111213141516171819202122232425262728 package jme2; import javax.microedition.midlet.MIDlet;import jdk.dio.DeviceManager;import jdk.dio.gpio.GPIOPin;import jdk.dio.gpio.GPIOPinConfig; public class Jme2 extends MIDlet { @Override public void startApp() { try { System.out.println("startApp"); //not ok GPIOPin led=DeviceManager.open(3); GPIOPinConfig cfg=new GPIOPinConfig.Builder().setPinNumber(3).setDirection(GPIOPinConfig.DIR_OUTPUT_ONLY).build(); final GPIOPin led=DeviceManager.open(cfg); do{ Thread.sleep(1000); led.setValue(!led.getValue()); System.out.println(" value :"+led.getValue()); }while(true); } catch (Exception ex) { ex.printStackTrace(); } } @Override public void destroyApp(boolean unconditional) { }} 运行项目到raspberrypi 注意: 接线 led 接 gpio 3+ gnd 参考: http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/RaspberryPi_GPIO/RaspberryPi_GPIO.html https://www.raspberrypi.org/documentation/usage/gpio-plus-and-raspi2/README.md