ESP32Servo
src
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
}
noTone
void noTone(int pin)
Definition:
ESP32Tone.cpp:29
pwmFactory
ESP32PWM * pwmFactory(int pin)
Definition:
ESP32PWM.cpp:305
ESP32PWM::detachPin
void detachPin(int pin)
Definition:
ESP32PWM.cpp:250
ESP32PWM::attachPin
void attachPin(uint8_t pin)
Definition:
ESP32PWM.cpp:231
ESP32Tone.h
ESP32PWM::writeTone
double writeTone(double freq)
Definition:
ESP32PWM.cpp:194
ESP32PWM::attached
bool attached()
Definition:
ESP32PWM.h:56
APin
int APin
Definition:
PWMExample.ino:2
pin
int pin
Definition:
ToneExample.ino:7
tone
void tone(int APin, unsigned int frequency)
Definition:
ESP32Tone.cpp:11
ESP32PWM
Definition:
ESP32PWM.h:17
Generated by
1.8.13