Presentation is loading. Please wait.

Presentation is loading. Please wait.

手機透過藍芽與Arduino的連線 組員:陳孟辰、鄭程祐、范揚泰、詹鈞焱、呂偉民 專題題目:遙控坦克車.

Similar presentations


Presentation on theme: "手機透過藍芽與Arduino的連線 組員:陳孟辰、鄭程祐、范揚泰、詹鈞焱、呂偉民 專題題目:遙控坦克車."— Presentation transcript:

1 手機透過藍芽與Arduino的連線 組員:陳孟辰、鄭程祐、范揚泰、詹鈞焱、呂偉民 專題題目:遙控坦克車

2 我們主要是透過Amarino所提供的Library來做連線﹐ Amarino提供各種已開發Library專門對Android
與Arduino之間的連線﹐包括: Amarino.connect 建立連線 Amarino.disconnect 切斷連線 Amarino.sendDataToArduino 傳送訊號給Arduino

3 private String DEVICE_ADDRESS = "07:12:05:16:70:52"; //設定藍芽位址
1.首先先宣告藍芽位址 private String DEVICE_ADDRESS = "07:12:05:16:70:52"; //設定藍芽位址 2.呼叫Amarino.connect 建立連線 Amarino.connect(this, DEVICE_ADDRESS); //建立手機與Arduino連線

4 Button.OnClickListener() {
//按下各個按鍵時所呼叫的副程式 public void onClick(View v) { switch ((Integer) v.getTag()) { case 0: SetMacOnClick(); break; case 1: update_Forward(); case 2: update_Back(); case 3: update_Left(); case 4: update_Right(); case 5: update_Stop(); case 6: update_CamDown(); case 7: update_CamUp(); case 8: update_CamStop(); //當按下各個按鍵時所設定的setTag以供Case呼叫副程式 Button btnSetmac = (Button) ; btnSetmac.setTag(0); btnSetmac.setOnClickListener(btnOnClick); Button btnForward = (Button) btnForward.setTag(1); btnForward.setOnClickListener(btnOnClick); Button btnBack = (Button) btnBack.setTag(2); btnBack.setOnClickListener(btnOnClick); Button btnLeft = (Button) btnLeft.setTag(3); btnLeft.setOnClickListener(btnOnClick); Button btnRight = (Button) btnRight.setTag(4); btnRight.setOnClickListener(btnOnClick); Button btnStop = (Button) btnStop.setTag(5); btnStop.setOnClickListener(btnOnClick);

5 呼叫Amarino.sendDataToArduino對Arduino傳送字串
//case對應的副程式中,對藍芽位址所發出的字串 private void update_PowerVal() { Amarino.sendDataToArduino(this, DEVICE_ADDRESS, 'P', power_Val); } private void update_Forward() { Amarino.sendDataToArduino(this, DEVICE_ADDRESS, 'F', power_Val); private void update_Back() { Amarino.sendDataToArduino(this, DEVICE_ADDRESS, 'B', power_Val); private void update_Left() { Amarino.sendDataToArduino(this, DEVICE_ADDRESS, 'L', power_Val); private void update_Right() { Amarino.sendDataToArduino(this, DEVICE_ADDRESS, 'R', power_Val); private void update_Stop() { Amarino.sendDataToArduino(this, DEVICE_ADDRESS, 'S', 0); } private void update_CamDown(){ Amarino.sendDataToArduino(this,DEVICE_ADDRESS,'D',0); private void update_CamUp(){ Amarino.sendDataToArduino(this,DEVICE_ADDRESS,'U',0); private void update_CamStop(){ Amarino.sendDataToArduino(this,DEVICE_ADDRESS,'C',0);

6 呼叫Amarino.disconnect斷開連線
//跳出程式時自動斷開連線 @Override protected void onStop() { super.onStop(); Amarino.disconnect(this, DEVICE_ADDRESS); }


Download ppt "手機透過藍芽與Arduino的連線 組員:陳孟辰、鄭程祐、范揚泰、詹鈞焱、呂偉民 專題題目:遙控坦克車."

Similar presentations


Ads by Google