1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- const int lowestPin = 2;
- const int highestPin = 33;
- #include <ESP32Servo.h>
- Servo myservo;
- void setup() {
- Serial.begin(115200);
-
- ESP32PWM::allocateTimer(0);
- ESP32PWM::allocateTimer(1);
- ESP32PWM::allocateTimer(2);
- ESP32PWM::allocateTimer(3);
- }
- void loop() {
- if (!myservo.attached()) {
- myservo.setPeriodHertz(50);
- myservo.attach(33, 1000, 2000);
- }
- myservo.write(0);
-
- for (int thisPin = lowestPin; thisPin <= highestPin; thisPin++) {
- if (ESP32PWM::hasPwm(thisPin) &&
- (ESP32PWM::channelsRemaining() > 0 ||
- pwmFactory(thisPin) != NULL ||
- thisPin == 25 ||
- thisPin == 26)) {
- if (pwmFactory(thisPin) == NULL) {
- if (thisPin == 25 ||
- thisPin == 26) {
- Serial.println("DAC to pin " + String(thisPin));
- } else
- Serial.println("Writing to pin " + String(thisPin));
- pinMode(thisPin, OUTPUT);
- }
-
- for (int brightness = 0; brightness < 255; brightness++) {
- analogWrite(thisPin, brightness);
- delay(1);
- myservo.write(brightness);
- }
-
- for (int brightness = 255; brightness >= 0; brightness--) {
- analogWrite(thisPin, brightness);
- myservo.write(brightness);
- delay(1);
- }
- }
- }
- myservo.detach();
- delay(2000);
- }
|