Last active
August 29, 2015 14:02
-
-
Save akexorcist/49e581e7b6a7a3dcb0df to your computer and use it in GitHub Desktop.
ตัวอย่างแอปพลิเคชั่นเบื้องต้นเพื่อควบคุมบอร์ด IOIO หรือ IOIO-Q โดยจะสั่งให้ LED ที่อยู่บนบอร์ดติดดับตามที่กด Toggle Button ในแอปพลิเคชั่น
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
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.inex.ioioapp" | |
android:versionCode="1" | |
android:versionName="1.0" > | |
<uses-sdk | |
android:minSdkVersion="8" | |
android:targetSdkVersion="19" /> | |
<uses-permission android:name="android.permission.BLUETOOTH"/> | |
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> | |
<uses-permission android:name="android.permission.INTERNET"/> | |
<application | |
android:allowBackup="true" | |
android:icon="@drawable/ic_launcher" | |
android:label="@string/app_name" | |
android:theme="@style/AppTheme" > | |
<activity | |
android:name="com.inex.ioioapp.MainActivity" | |
android:label="@string/app_name" > | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN" /> | |
<category android:name="android.intent.category.LAUNCHER" /> | |
</intent-filter> | |
</activity> | |
</application> | |
</manifest> |
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
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:paddingBottom="@dimen/activity_vertical_margin" | |
android:paddingLeft="@dimen/activity_horizontal_margin" | |
android:paddingRight="@dimen/activity_horizontal_margin" | |
android:paddingTop="@dimen/activity_vertical_margin" > | |
<ToggleButton | |
android:id="@+id/toggleButton1" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_centerHorizontal="true" | |
android:layout_centerVertical="true" | |
android:text="ToggleButton" /> | |
</RelativeLayout> |
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
package com.inex.ioioapp; | |
import ioio.lib.api.DigitalOutput; | |
import ioio.lib.api.exception.ConnectionLostException; | |
import ioio.lib.util.BaseIOIOLooper; | |
import ioio.lib.util.IOIOLooper; | |
import ioio.lib.util.android.IOIOActivity; | |
import android.os.Bundle; | |
import android.widget.Toast; | |
import android.widget.ToggleButton; | |
public class MainActivity extends IOIOActivity { | |
ToggleButton toggleButton1; | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.layout_main); | |
toggleButton1 = (ToggleButton)findViewById(R.id.toggleButton1); | |
} | |
class Looper extends BaseIOIOLooper { | |
DigitalOutput dout; | |
protected void setup() throws ConnectionLostException | |
, InterruptedException { | |
dout = ioio_.openDigitalOutput(0, false); | |
runOnUiThread(new Runnable() { | |
public void run() { | |
Toast.makeText(getApplicationContext() | |
, "Connected!!", Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
} | |
public void loop() throws ConnectionLostException | |
, InterruptedException { | |
dout.write(!toggleButton1.isChecked()); | |
Thread.sleep(50); | |
} | |
public void disconnected() { | |
runOnUiThread(new Runnable() { | |
public void run() { | |
Toast.makeText(getApplicationContext() | |
, "Disconnect!!", Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
} | |
public void incompatible() { | |
} | |
} | |
protected IOIOLooper createIOIOLooper() { | |
return new Looper(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment