ESP32Servo
PWMExample.ino
Go to the documentation of this file.
1 #include <ESP32Servo.h>
2 int APin = 13;
4 int freq = 1000;
5 void setup() {
6  // Allow allocation of all timers
11  Serial.begin(115200);
12  pwm.attachPin(APin, freq, 10); // 1KHz 8 bit
13 
14 }
15 void loop() {
16 
17  // fade the LED on thisPin from off to brightest:
18  for (float brightness = 0; brightness <= 0.5; brightness += 0.001) {
19  // Write a unit vector value from 0.0 to 1.0
20  pwm.writeScaled(brightness);
21  delay(2);
22  }
23  //delay(1000);
24  // fade the LED on thisPin from brithstest to off:
25  for (float brightness = 0.5; brightness >= 0; brightness -= 0.001) {
26  freq += 10;
27  // Adjust the frequency on the fly with a specific brightness
28  // Frequency is in herts and duty cycle is a unit vector 0.0 to 1.0
29  pwm.adjustFrequency(freq, brightness); // update the time base of the PWM
30  delay(2);
31  }
32  // pause between LEDs:
33  delay(1000);
34  freq = 1000;
35  pwm.adjustFrequency(freq, 0.0); // reset the time base
36 }
void adjustFrequency(double freq, float dutyScaled=-1)
Definition: ESP32PWM.cpp:180
static void allocateTimer(int timerNumber)
Definition: ESP32PWM.cpp:25
void loop()
Definition: PWMExample.ino:15
void attachPin(uint8_t pin)
Definition: ESP32PWM.cpp:231
int freq
Definition: PWMExample.ino:4
ESP32PWM pwm
Definition: PWMExample.ino:3
void setup()
Definition: PWMExample.ino:5
int APin
Definition: PWMExample.ino:2
void writeScaled(float duty)
Definition: ESP32PWM.cpp:159