首頁 > 評測 > FireBeetle Board-ESP32——HttpServer&Touch IO
FireBeetle Board-ESP32——HttpServer&Touch IO
- [導讀]
- 本文展示了如何使用Arduino的IDE在Firebeetle ESP32中構建一個網(wǎng)絡服務器以及使用touchIO來配置一個觸摸按鍵。
通常情況下會想要通過訪問網(wǎng)頁來實現(xiàn)對某些設備的操作和控制,在arm平臺上建立httpserver,使用lwip協(xié)議棧的話開啟SSI和CGI就可以比較容易的實現(xiàn)上述想法。那么在arduino中,同樣可以創(chuàng)建網(wǎng)絡服務器,一下舉個例子
需要的庫就是FireBeetle Board-ESP32提供的
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();
// the content of the HTTP response follows the header:
client.print("
LED Control
");
client.print("Turn On The LED
");
client.print("Turn Off The LED
");
// The HTTP response ends with another blank line:
client.println();
// break out of the while loop:
break;
} else { // if you got a newline, then clear currentLine:
currentLine = "";
}
} else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
以上實現(xiàn)了發(fā)送http頭和內容,假如要控制一個led,還需要發(fā)送點亮或者關閉的請求,然后解析后執(zhí)行IO動作。
以下就是對應的IO操作,2端口就是D9,連接到板載的LED.
// Check to see if the client request was "GET /H" or "GET /L":
if (currentLine.endsWith("GET /H")) {
digitalWrite(2, HIGH); // GET /H turns the LED on
}
if (currentLine.endsWith("GET /L")) {
digitalWrite(2, LOW); // GET /L turns the LED off
}
無線開啟后搜索程序中制定的AP并連接,然后我們可以訪問模塊在路由器中獲得的IP地址,調試程序在串口也會輸出這些信息。
點擊鏈接就可以操作模塊上的LED了,這就是實現(xiàn)網(wǎng)頁控制的基本原型。除此之外,還有值得一提的地方是FireBeetle Board-ESP32 提供了多達 10 個電容式傳感器 GPIO,能夠探測由手指或其他物品直接接觸或 接近而產(chǎn)生的電容差異。這種低噪聲特性和電路的高靈敏度設計適用于較小的觸摸板,可以直接用于觸摸開關。
接下來測試一下是否如實。
查找?guī)煳募,簡單書寫下面代碼
//觸摸IO測試
void setup() {
Serial.begin(115200);
delay(1000); // give me time to bring up serial monitor
Serial.println("FireBeetle Board-ESP32 Touch Test");
}
//10 個具有觸摸傳感器的IO,D0-D9,即T0-T9
void loop(){
//讀取IO 狀態(tài)
Serial.println(touchRead(T2)); // get value using T0->D9
delay(1000);
}
然后直接用手去觸摸IO,通過串口監(jiān)視器看到如下,在有手指觸摸的時候會變?yōu)楦唠娖?/p>

這樣的功能可以的確可以嘗試作為電容觸摸按鍵了。后續(xù)準備還是回到C環(huán)境下了,不過不否定Arduino是很好用的
-
- 本文系21ic原創(chuàng),未經(jīng)許可禁止轉載!
網(wǎng)友評論
- 聯(lián)系人:巧克力娃娃
- 郵箱:board@21ic.com
- 我要投稿
-
歡迎入駐,開放投稿
-
人均百萬?英偉達中國員工收入曝光! 2024-08-29
-
《黑神話:悟空》玩家硬盤升級攻略:提升游戲體驗,暢享3A大作 2024-08-29
-
數(shù)睿數(shù)據(jù)參加《系統(tǒng)與軟件工程 低代碼開發(fā)平臺通用技術要求》國家標準編制 2024-08-29
- NRF52810藍牙數(shù)字耳機找人定制
預算:¥30005天前
- 125KW模塊式PCS軟硬件外包開發(fā)
預算:¥1100000015小時前
- 12V汽車啟動電源項目BMS設計
預算:¥50000023小時前
- 數(shù)據(jù)可視化軟件 開發(fā)
預算:¥5000023小時前
- PLC項目調試修改
預算:¥100001天前
- 起動電機控制器開發(fā)
預算:¥1100001天前