0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

helloLedJNI

Posted at

のコードに変えただけです。^^;

LedJNI.java
package ledJNI;

public class LedJNI {
    static {
        System.loadLibrary("LedJNIImpl");
    }

    public native void ledOn();
    
    public static void main(String[] args) {
        new LedJNI().ledOn();
    }
}
LedJNIImple.c
#include <jni.h>
#include "LedJNI.h"
#include <stdio.h>
#include <wiringPi.h>
#define LED 17  // 17ピンからLEDのプラス端子に印加

JNIEXPORT void JNICALL Java_LedJNI_ledOn(JNIEnv *env, jobject obj) {
        wiringPiSetupSys();

        pinMode(LED, OUTPUT);

        for (int i=0 ; i < 5 ; i++) {
                digitalWrite(LED, HIGH);  //オン
                delay(500);
                digitalWrite(LED, LOW);   //オフ
                delay(500);
        }
        return;
}
sudo apt-get install wiringpi

③ 共有ライブラリのコンパイル

gcc -shared -o libLedJNIImpl.so -I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux LedJNIImpl.c -lwiringPi

実行

java -Djava.library.path=. LedJNI
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?