chinese直男口爆体育生外卖, 99久久er热在这里只有精品99, 又色又爽又黄18禁美女裸身无遮挡, gogogo高清免费观看日本电视,私密按摩师高清版在线,人妻视频毛茸茸,91论坛 兴趣闲谈,欧美 亚洲 精品 8区,国产精品久久久久精品免费

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

如何使用Android應(yīng)用程序控制arduino IO引腳

454398 ? 來源:網(wǎng)絡(luò)整理 ? 作者:佚名 ? 2019-11-06 17:47 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

步驟1:部件

對(duì)于這個(gè)instructables你需要幾個(gè)部分。

一個(gè)arduino

一個(gè)Android智能手機(jī)或平板電腦(我正在使用android 5.0.1)

以太網(wǎng)屏蔽

3 Led

3 220歐姆電阻

一些跳線

a breadboard

安裝了android studio的計(jì)算機(jī)

步驟2:以太網(wǎng)盾

我從gearbest.com獲得了這個(gè)以太網(wǎng)屏蔽。

它立即在我的arduino mega(也來自gearbest.com)上工作

在屏蔽上你有2個(gè)SPI設(shè)備。 SD卡讀卡器和用于以太網(wǎng)的W5100 IC。

在這個(gè)instructables中,我們只使用以太網(wǎng)部件。

步驟3:架構(gòu)

我們需要將3個(gè)led連接到arduino。您可以使用除引腳0,1,10到13和50到53之外的每個(gè)引腳。

我使用的是引腳22,引腳23和引腳24.

您還需要將arduino連接到你的本地網(wǎng)絡(luò)。不需要互聯(lián)網(wǎng)。

第4步:Arduino草圖

對(duì)于arduino草圖,我從示例網(wǎng)絡(luò)服務(wù)器草圖開始。

我嘗試記錄每一件事,但如果你有問題可以隨意提問!

#include

#include

// Set the MAC address

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};

// Set the IP address

IPAddress ip(192, 168, 1, 177);

// Start a server at port 80 (http)

EthernetServer server(80);

void setup() {

// Open serial communications

Serial.begin(9600);

// start the Ethernet connection and the server

Ethernet.begin(mac, ip);

server.begin();

// Pin 22 - 24 output (leds)

pinMode(22, OUTPUT);

pinMode(23, OUTPUT);

pinMode(24, OUTPUT);

}

void loop() {

// Check if client connected

EthernetClient client = server.available();

if (client) { // If there is a client.。.

boolean currentLineIsBlank = true;

String buffer = “”; // A buffer for the GET request

while (client.connected()) {

if (client.available()) {

char c = client.read();// Read the data of the client

buffer += c; // Store the data in a buffer

if (c == ‘ ’ && currentLineIsBlank) {// if 2x new line ==》 Request ended

// send a standard http response header

client.println(“HTTP/1.1 200 OK”);

client.println(“Content-Type: text/html”);

client.println(“Connection: close”);

client.println(); // Blank line ==》 end response

break;

}

if (c == ‘ ’) { // if New line

currentLineIsBlank = true;

buffer = “”; // Clear buffer

} else if (c == ‘ ’) { // If cariage return.。.

//Read in the buffer if there was send “GET /?。..”

if(buffer.indexOf(“GET /?led1=1”)》=0) { // If led1 = 1

digitalWrite(24, HIGH); // led 1 》 on

}

if(buffer.indexOf(“GET /?led1=0”)》=0) { // If led1 = 0

digitalWrite(24, LOW); // led 1 》 off

}

if(buffer.indexOf(“GET /?led2=1”)》=0) { // If led2 = 1

digitalWrite(22, HIGH); // led 2 》 on

}

if(buffer.indexOf(“GET /?led2=0”)》=0) { // If led2 = 0

digitalWrite(22, LOW); // led 2 》 off

}

if(buffer.indexOf(“GET /?led3=1”)》=0) { // If led3 = 1

digitalWrite(23, HIGH); // led 3 》 on

}

if(buffer.indexOf(“GET /?led3=0”)》=0) { // If led3 = 0

digitalWrite(23, LOW); // led 3 》 off

}

} else {

currentLineIsBlank = false;

}

}

}

delay(1);

client.stop();

}

}

那是arduino上的代碼。

很簡(jiǎn)單,對(duì)吧?讓我們?nèi)タ纯磻?yīng)用程序吧!

第5步:應(yīng)用程序布局

為了創(chuàng)建一個(gè)android工作室項(xiàng)目我會(huì)在這里重定向你。開頭是相同的,選擇一個(gè)名稱并創(chuàng)建主要活動(dòng),但在刪除“hello world” textview后,您需要添加任意類型的3個(gè)按鈕。我正在使用開關(guān),切換按鈕和普通按鈕,但您可以選擇最喜歡的。

注意:

如果出現(xiàn)渲染錯(cuò)誤,請(qǐng)?jiān)诖翱陧敳繉?Apptheme 更改為 Appcompat.NoActionBar

!注意!

正常按鈕只會(huì)在按下時(shí)點(diǎn)亮它的LED。釋放按鈕后led將熄滅。

在 res/values/styles.xml 中,您需要將父級(jí)更改為:“Theme.Appcompat.NoActionBar”

好的,現(xiàn)在我們可以開始編寫應(yīng)用程序了!

第6步:應(yīng)用程序編碼

為了對(duì)應(yīng)用進(jìn)行編碼,我讓您更輕松。您需要將此代碼復(fù)制到 MainActivity.java ,并將包 laurens_wuyts.arduinoiocontrol 更改為 company.appname 。

package laurens_wuyts.arduinoiocontrol;

import android.app.Activity;

import android.os.AsyncTask;

import android.support.v7.app.ActionBarActivity;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.view.MotionEvent;

import android.view.View;

import android.widget.Button;

import android.widget.CompoundButton;

import android.widget.Switch;

import android.widget.ToggleButton;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.net.HttpURLConnection;

import java.net.URL;

public class MainActivity extends Activity{

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.menu_main, menu);

return true;

}

@Override

public boolean onOptionsItemSelected(MenuItem item) {

// Handle action bar item clicks here. The action bar will

// automatically handle clicks on the Home/Up button, so long

// as you specify a parent activity in AndroidManifest.xml.

int id = item.getItemId();

//noinspection SimplifiableIfStatement

if (id == R.id.action_settings) {

return true;

}

return super.onOptionsItemSelected(item);

}

/*****************************************************/

/* This is a background process for connecting */

/* to the arduino server and sending */

/* the GET request withe the added data */

/*****************************************************/

private class Background_get extends AsyncTask {

@Override

protected String doInBackground(String.。. params) {

try {

/*********************************************************/

/* Change the IP to the IP you set in the arduino sketch */

/*********************************************************/

URL url = new URL(“http://192.168.1.177/?” + params[0]);

HttpURLConnection connection = (HttpURLConnection) url.openConnection();

BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));

StringBuilder result = new StringBuilder();

String inputLine;

while ((inputLine = in.readLine()) != null)

result.append(inputLine).append(“ ”);

in.close();

connection.disconnect();

return result.toString();

} catch (IOException e) {

e.printStackTrace();

}

return null;

}

}

}

在此代碼中,您只需要將IP更改為arduino的IP。

要檢查按鈕,您需要做兩件事:

定義按鈕

為每個(gè)按鈕添加onclick/onchange監(jiān)聽器。

定義按鈕:

/* For a switch */

Switch led1 = (Switch) findViewById(R.id.Led1);

/* For a toggle button */

ToggleButton led2 = (ToggleButton) findViewById(R.id.Led2);

/* For a normal button */

Button led3 = (Button) findViewById(R.id.Led3);

添加onclick/onchange:

將onclick/onchange偵聽器放在onCreate函數(shù)中。

/* For a switch you‘ll need an “OnCheckedChangeListener” like this */

led1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

if (isChecked) {

/* Switch is led 1 */

new Background_get().execute(“l(fā)ed1=1”);

} else {

new Background_get().execute(“l(fā)ed1=0”);

}

}

});

/* For a toggle button you also need a “OnCheckedChangeListener” */

led2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

if(isChecked) {

/* Toggle button is led 2 */

new Background_get().execute(“l(fā)ed2=1”);

} else {

new Background_get().execute(“l(fā)ed2=0”);

}

}

});

/* For a button you’ll need a “OnTouchListener” */

led3.setOnTouchListener(new View.OnTouchListener() {

@Override

public boolean onTouch(View v, MotionEvent event) {

if (event.getAction() == MotionEvent.ACTION_DOWN) {

/* button is led 3 */

new Background_get().execute(“l(fā)ed3=1”);

} else if (event.getAction() == MotionEvent.ACTION_UP) {

new Background_get().execute(“l(fā)ed3=0”);

}

return true;

}

});

這就是所有編碼這需要做!現(xiàn)在我們需要為您的應(yīng)用添加權(quán)限。

步驟7:向您的應(yīng)用添加權(quán)限

讓您的應(yīng)用運(yùn)行你需要賦予它權(quán)限。我們只需要1個(gè)權(quán)限:上網(wǎng)。要獲得此權(quán)限,您需要打開清單文件并添加:

步驟8:恢復(fù)

在這個(gè)教程中,我向您展示了如何通過網(wǎng)絡(luò)從Android手機(jī)控制arduino IO引腳。

我還為想要使用它的人提供了完整的應(yīng)用程序目錄。

責(zé)任編輯:wv

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • Android
    +關(guān)注

    關(guān)注

    12

    文章

    3980

    瀏覽量

    132468
  • Arduino
    +關(guān)注

    關(guān)注

    190

    文章

    6509

    瀏覽量

    194948
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評(píng)論

    相關(guān)推薦
    熱點(diǎn)推薦

    S7-200 可編程序控制器系統(tǒng)手冊(cè)

    電子發(fā)燒友網(wǎng)站提供《S7-200 可編程序控制器系統(tǒng)手冊(cè).pdf》資料免費(fèi)下載
    發(fā)表于 09-02 16:24 ?5次下載

    當(dāng)ICE_DAT引腳和ICE_CLK引腳應(yīng)用程序代碼中配置為備用功能時(shí),是否會(huì)導(dǎo)致編程失???

    當(dāng)ICE_DAT引腳和ICE_CLK引腳應(yīng)用程序代碼中配置為備用功能時(shí),是否會(huì)導(dǎo)致編程失???
    發(fā)表于 08-25 06:55

    對(duì)于具有直接反饋控制的 CCG3PA 應(yīng)用程序,是否可以正確地重新使用引腳 12(負(fù)載使能控制),它有哪些限制?

    對(duì)于具有直接反饋控制的 CCG3PA 應(yīng)用程序,是否可以正確地重新使用引腳 12(負(fù)載使能控制),它有哪些限制? 我們能夠?qū)⑵渲貜?fù)用于通信,但是當(dāng)使用 \"
    發(fā)表于 05-26 07:23

    是否有辦法用標(biāo)準(zhǔn)Windows驅(qū)動(dòng)程序控制GPIO嗎?

    問題。 CY7C65213-28PVXI 的 GPIO 控制使用“cyusbserial.dll”執(zhí)行 由CYPRESS?提供, 但我發(fā)現(xiàn)該 dll 不能與標(biāo)準(zhǔn) Windows 驅(qū)動(dòng)程序一起使用。 您能告訴我是否有辦法用標(biāo)準(zhǔn) Windows 驅(qū)動(dòng)
    發(fā)表于 05-08 07:05

    射頻類的ADC和非射頻類ADC在電路設(shè)計(jì),以及程序控制上是否完全一致?

    請(qǐng)問: 通常射頻類的ADC例如 ADC12D1800RF, 與其非射頻類ADC12D1800,在電路設(shè)計(jì),以及程序控制上是否完全一致。 還是用于射頻時(shí),在程序中會(huì)增加一些協(xié)議定義之類?
    發(fā)表于 01-23 06:07

    BQ78412應(yīng)用程序編程接口

    電子發(fā)燒友網(wǎng)站提供《BQ78412應(yīng)用程序編程接口.pdf》資料免費(fèi)下載
    發(fā)表于 12-18 14:46 ?0次下載
    BQ78412<b class='flag-5'>應(yīng)用程序</b>編程接口

    TAS2521應(yīng)用程序參考指南

    電子發(fā)燒友網(wǎng)站提供《TAS2521應(yīng)用程序參考指南.pdf》資料免費(fèi)下載
    發(fā)表于 12-10 13:49 ?0次下載
    TAS2521<b class='flag-5'>應(yīng)用程序</b>參考指南

    android手機(jī)上emulate應(yīng)用程序的方法

    Android手機(jī)上模擬(emulate)應(yīng)用程序的方法通常涉及到使用Android模擬器(Emulator)或類似的工具來模擬Android環(huán)境,以便在沒有實(shí)際物理設(shè)備的情況下運(yùn)行
    的頭像 發(fā)表于 12-05 15:33 ?1846次閱讀

    AWTK-WEB 快速入門(2) - JS 應(yīng)用程序

    導(dǎo)讀AWTK可以使用相同的技術(shù)棧開發(fā)各種平臺(tái)的應(yīng)用程序。有時(shí)我們需要使用Web界面與設(shè)備進(jìn)行交互,本文介紹一下如何使用JS語言開發(fā)AWTK-WEB應(yīng)用程序。用AWTKDesigner新建一個(gè)應(yīng)用程序先安裝AWTKDesigner
    的頭像 發(fā)表于 12-05 01:04 ?686次閱讀
    AWTK-WEB 快速入門(2) - JS <b class='flag-5'>應(yīng)用程序</b>

    HAL庫在Arduino平臺(tái)上的使用

    ,適合于快速原型開發(fā)和教育。HAL(硬件抽象層)庫是一種在Arduino平臺(tái)上使用的軟件庫,它提供了一種標(biāo)準(zhǔn)化的方式來訪問硬件功能,使得開發(fā)者可以編寫更通用、更可移植的代碼。 1. 什么是HAL庫 HAL庫是硬件抽象層庫的簡(jiǎn)稱,它是一種軟件架構(gòu),用于將硬件特定的代碼與應(yīng)用程序
    的頭像 發(fā)表于 12-02 14:04 ?2068次閱讀

    AWTK-WEB 快速入門(1) - C 語言應(yīng)用程序

    導(dǎo)讀AWTK可以使用相同的技術(shù)棧開發(fā)各種平臺(tái)的應(yīng)用程序。有時(shí)我們需要使用Web界面與設(shè)備進(jìn)行交互,本文介紹一下如何使用C語言開發(fā)AWTK-WEB應(yīng)用程序。用AWTKDesigner新建一個(gè)應(yīng)用程序
    的頭像 發(fā)表于 11-27 11:46 ?1017次閱讀
    AWTK-WEB 快速入門(1) - C 語言<b class='flag-5'>應(yīng)用程序</b>

    arduino 6軸同步電機(jī)驅(qū)動(dòng)程序

    arduino 6軸同步電機(jī)驅(qū)動(dòng)程序。含加加減速。
    發(fā)表于 11-09 14:09 ?0次下載

    Arduino程序:實(shí)現(xiàn)SD NAND(貼片sd卡)的讀寫功能

    引腳對(duì)應(yīng) []()   下載程序 沒有錯(cuò)誤的話會(huì)出現(xiàn)如下的內(nèi)容 []()   使用SPI讀寫的話,我看他們官網(wǎng)博客上沒有連接相應(yīng)的電阻,直接接IO口上了   下面是官方提供的SPI連接示意圖
    發(fā)表于 11-07 17:45

    華納云監(jiān)視Linux磁盤IO性能命令:iotop,iostat,vmstat,atop,dstat,ioping

    問題( input/output )是Linux系統(tǒng)性能不佳的最常見原因之一。當(dāng)應(yīng)用程序試圖在存儲(chǔ)設(shè)備(例如硬盤驅(qū)動(dòng)器、SAN和NAS)上快速讀取或?qū)懭脒^多數(shù)據(jù)時(shí),就會(huì)發(fā)生這種情況,這迫使應(yīng)用程序和用戶等待
    的頭像 發(fā)表于 10-24 14:43 ?1152次閱讀

    PCM2912應(yīng)用程序的操作環(huán)境

    電子發(fā)燒友網(wǎng)站提供《PCM2912應(yīng)用程序的操作環(huán)境.pdf》資料免費(fèi)下載
    發(fā)表于 10-21 09:33 ?0次下載
    PCM2912<b class='flag-5'>應(yīng)用程序</b>的操作環(huán)境