我对使用 esp32 开发板进行编程非常陌生 我编写了一个代码示例,可以让我借助一个名为 Arduino BlueControl 应用程序的应用程序打开我的无源蜂鸣器,我设法通过电话和电路板进行通信并制作蜂鸣器响,但我在我的应用程序的帮助下无法关闭我的电路板这是我的代码示例:
#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#endif
BluetoothSerial SerialBT;
int command = 0;
int freq = 2000;
int channel = 0;
int resolution = 8;
void setup() {
ledcSetup(channel, freq, resolution);
ledcAttachPin(12, channel);
Serial.begin(115200);
SerialBT.begin("ESP32test"); //Bluetooth device name
Serial.println("The device started, now you can pair it with Bluetooth!");
}
void loop() {
if (SerialBT.available()) {
command = SerialBT.read();
Serial.write(command);
if(command = 1) {
ledcWriteTone(channel, 2000);
for (int dutyCycle = 0; dutyCycle <= 255; dutyCycle=dutyCycle+10){
Serial.println(dutyCycle);
ledcWrite(channel, dutyCycle);
delay(1000);
}
command = '0';
}
}
delay(20);
}