www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

首頁 > 評測 > FireBeetle Board-ESP32——HttpServer&Touch IO

FireBeetle Board-ESP32——HttpServer&Touch IO

FireBeetle   Board   ESP32   HttpServer   Touch IO   
  • 作者:BinWin
  • 來源:21ic
  • [導讀]
  • 本文展示了如何使用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提供的,http使用常用80端口,接下來使用庫函數(shù)來發(fā)送請求和回復應答就可以

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地址,調試程序在串口也會輸出這些信息。

q.jpg

點擊鏈接就可以操作模塊上的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>

 

p.jpg

 

這樣的功能可以的確可以嘗試作為電容觸摸按鍵了。后續(xù)準備還是回到C環(huán)境下了,不過不否定Arduino是很好用的

  • 本文系21ic原創(chuàng),未經(jīng)許可禁止轉載!

網(wǎng)友評論