[vc_row][vc_column][vc_column_text]![]()
Linker Tilt module is one module of the Linker series.
It is made up of a metal ball with two touching point inside and it can detect the tile in a low cost way.
It costs much less and easier to use compared to the gyroscope .[/vc_column_text][vc_tour][vc_tab title=”Parts List” tab_id=”1393924554-1-90″][vc_column_text]1. 1 x [bigcommerce link=”/pcduino-v2-an-minipc-with-arduino-headers-ubuntu-android-google/” target=”_blank”]pcDuino V2[/bigcommerce] v2
2. 1 x [bigcommerce link=”/base-shield-of-linker-kit-for-pcduino-arduino/” target=”_blank”]Linker base shield[/bigcommerce]
3. 1 x linker kit 20cm cable
4. 1 x Linker tilt [/vc_column_text][/vc_tab][vc_tab title=”Wiring diagram” tab_id=”1393924554-2-0″][vc_column_text]
linker tilt – > GPIO 9 with linker kit 20cm cable then power on the pcDuino[/vc_column_text][/vc_tab][vc_tab title=”Test code” tab_id=”1393982899269-2-10″][vc_column_text]//GPIO Control Class
package com.test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class GPIO_Pin {
private String modeURI = "/sys/devices/virtual/misc/gpio/mode/";
private String statusURI = "/sys/devices/virtual/misc/gpio/pin/";
private int pin = 0;
public static final String HIGH = "1", LOW = "0", INPUT = "0", OUTPUT = "1", INPUT_PU = "8";
public GPIO_Pin(int pin) {
modeURI += "gpio" + pin;
statusURI += "gpio" + pin;
this.pin = pin;
}
public GPIO_Pin(String pin) {
// Finalize file paths
modeURI += "gpio" + pin;
statusURI += "gpio" + pin;
this.pin =Integer.parseInt(pin);
}
public int getPin() {
return pin;
}
public void overrideURI(String uri) {
modeURI = uri + "mode/gpio" + pin;
statusURI = uri + "pin/gpio" + pin;
}
public void setMode(String mode) {
writeToFile(getModeURI(), mode);
}
public void set(String state) {
writeToFile(getStatusURI(), state);
}
public void setHIGH() {
writeToFile(getStatusURI(), HIGH);
}
public void setLOW() {
writeToFile(getStatusURI(), LOW);
}
public void setModeINPUT() {
writeToFile(getModeURI(), INPUT);
}
public void setModeOUTPUT() {
writeToFile(getModeURI(), OUTPUT);
}
public void setModeINPUT_PU() {
writeToFile(getModeURI(), INPUT_PU);
}
public String getModeURI() {
return modeURI;
}
public String getStatusURI() {
return statusURI;
}
public String getPinMode() {
try {
BufferedReader reader = new BufferedReader(new FileReader(getModeURI()));
String data = reader.readLine();
reader.close();
return data;
} catch (IOException e) {
}
return "";
}
public String getPinStatus() {
try {
BufferedReader reader = new BufferedReader(new FileReader(getStatusURI()));
String data = reader.readLine();
reader.close();
return data;
} catch (IOException e) {
}
return "";
}
private void writeToFile(String URI, String data) {
try {
File file = new File(URI);
file.delete();
File newFile = new File(URI);
newFile.createNewFile();
FileWriter writer = new FileWriter(URI);
writer.write(data);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws InterruptedException {
GPIO_Pin ledpin=new GPIO_Pin(1);
ledpin.setModeOUTPUT();
while (true) {
ledpin.setHIGH();
Thread.sleep(400);
ledpin.setLOW();
Thread.sleep(400);
}
}
}
Test Code:
package com.test;
public class test {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
GPIO_Pin buttenpin=new GPIO_Pin(9);
buttenpin.setModeINPUT();
while (true) {
System.out.println(buttenpin.getPinStatus() );
Thread.sleep(4);
}
}
}
[/vc_column_text][/vc_tab][vc_tab title=”Test result” tab_id=”1393982900285-3-3″][vc_column_text]you can see the output at the console.
It will output 1 when there is a tile event.

Leave a Reply
You must be logged in to post a comment.