ESP32Servo
ESP32Tone.cpp
Go to the documentation of this file.
1 /*
2  * ESP32Tone.cpp
3  *
4  * Created on: Sep 23, 2018
5  * Author: hephaestus
6  */
7 
8 
9 #include "ESP32Tone.h"
10 
11 void tone(int APin,unsigned int frequency){
12  ESP32PWM* chan = pwmFactory(APin);
13  if (chan == NULL) {
14  chan = new ESP32PWM();
15  }
16  if(!chan->attached()){
17  chan->attachPin(APin,frequency, 10); // This adds the PWM instance to the factory list
18  //Serial.println("Attaching tone : "+String(APin)+" on PWM "+String(chan->getChannel()));
19  }
20  chan->writeTone(frequency);// update the time base of the PWM
21 }
22 
23 void tone(int pin, unsigned int frequency, unsigned long duration){
24  tone(pin,frequency);
25  delay(duration);
26  noTone(pin);
27 }
28 
29 void noTone(int pin){
30  ESP32PWM* chan = pwmFactory(pin);
31  if (chan != NULL) {
32  if(chan->attached())
33  {
34  chan->detachPin(pin);
35  delete chan;
36  }
37  }
38 }
void noTone(int pin)
Definition: ESP32Tone.cpp:29
ESP32PWM * pwmFactory(int pin)
Definition: ESP32PWM.cpp:305
void detachPin(int pin)
Definition: ESP32PWM.cpp:250
void attachPin(uint8_t pin)
Definition: ESP32PWM.cpp:231
double writeTone(double freq)
Definition: ESP32PWM.cpp:194
bool attached()
Definition: ESP32PWM.h:56
int APin
Definition: PWMExample.ino:2
int pin
Definition: ToneExample.ino:7
void tone(int APin, unsigned int frequency)
Definition: ESP32Tone.cpp:11