/*******************************************************
  ESP32PWM控制蜂鸣器
  功能：实现蜂鸣器发出一定频率的声音
  引脚：Ｄ12(GPIO12)
  Designer: Code_Mouse
  Date:2018-8-27
*******************************************************/
int freq = 2000;
int channel = 0;
int resolution = 8;
void setup() {
  Serial.begin(115200);
  ledcSetup(channel, freq, resolution);
  ledcAttachPin(12, channel);
}
void loop() {
  ledcWriteTone(channel, 2000);
  for (int dutyCycle = 0; dutyCycle <= 255; dutyCycle = dutyCycle + 10) {
    Serial.println(dutyCycle);
    ledcWrite(channel, dutyCycle);
    delay(1000);
  }
  ledcWrite(channel, 125);
  for (int freq = 255; freq < 10000; freq = freq + 250) {
    Serial.println(freq);
    ledcWriteTone(channel, freq);
    delay(1000);
  }
}
