Created
June 28, 2014 08:43
-
-
Save skrb/64a339446e42a1c3fb49 to your computer and use it in GitHub Desktop.
BlinkLED.java
This file contains 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
/* | |
* Java Embedded Raspberry Pi GPIO app | |
* エルチカ♪ | |
* * 用意するもの | |
* ジャンパーケーブル(オス×メス:2本) | |
* LED(RED 3.3v) | |
* 抵抗 470Ω(黄・紫・茶・金) | |
*/ | |
import java.io.File; | |
import java.io.FileWriter; | |
public class BlinkLED { | |
static final String GPIO_OUT = "out"; | |
static final String GPIO_ON = "1"; | |
static final String GPIO_OFF = "0"; | |
static final String GPIO_CH = "18"; | |
public static void main(String[] args) { | |
try { | |
//Refresh GPIO_CH | |
FileWriter unexport = new FileWriter("/sys/class/gpio/unexport"); | |
FileWriter export = new FileWriter("/sys/class/gpio/export"); | |
// Reset GPIO17 | |
File exportFileCheck = new File("/sys/class/gpio/gpio" + GPIO_CH); | |
if (exportFileCheck.exists()) { | |
unexport.write(GPIO_CH); | |
unexport.flush(); | |
} | |
export.write(GPIO_CH); | |
export.flush(); | |
//Direction GPIO_CH | |
FileWriter direction = new FileWriter("/sys/class/gpio/gpio" + GPIO_CH + "/direction"); | |
direction.write(GPIO_OUT); | |
direction.flush(); | |
// Create GPIO Writer | |
FileWriter command = new FileWriter("/sys/class/gpio/gpio" + GPIO_CH + "/value"); | |
// Brink Write | |
for (int i = 0; i < 100; i++) { | |
command.write(GPIO_ON); | |
command.flush(); | |
Thread.sleep(200); | |
command.write(GPIO_OFF); | |
command.flush(); | |
Thread.sleep(200); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment