You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

69 lines
1.6 KiB

/*
ESP32 mDNS responder sample
This is an example of an HTTP server that is accessible
via http://esp32.local URL thanks to mDNS responder.
Instructions:
- Update WiFi SSID and password as necessary.
- Flash the sketch to the ESP32 board
- Install host software:
- For Linux, install Avahi (http://avahi.org/).
- For Windows, install Bonjour (http://www.apple.com/support/bonjour/).
- For Mac OSX and iOS support is built in through Bonjour already.
- Point your browser to http://esp32.local, you should see a response.
*/
#include "esp32-hal-ledc.h"
const char* ssid = "ssid";
const char* password = "password";
#define SERVO_LOW 8000
#define SERVO_HIGH 3000
#define SERVO_CHANNEL_0 5
#define SERVO_CHANNEL_1 18
const int buttonPin = 0;
int servoChannel=SERVO_CHANNEL_0;
#define TIMER_WIDTH 16
void setup(void)
{
Serial.begin(115200);
pinMode(buttonPin, INPUT_PULLUP);
ledcSetup(1, 50, TIMER_WIDTH);
ledcAttachPin(SERVO_CHANNEL_0,1);
ledcWrite(1, SERVO_LOW);
delay(1000);
ledcDetachPin(SERVO_CHANNEL_0);
delay(100);
ledcSetup(1, 50, TIMER_WIDTH);
ledcAttachPin(SERVO_CHANNEL_1,1);
ledcWrite(1, SERVO_LOW);
delay(1000);
ledcDetachPin(SERVO_CHANNEL_1);
}
void loop(void)
{
if (digitalRead(buttonPin) == LOW) {
if (servoChannel==SERVO_CHANNEL_0) servoChannel=SERVO_CHANNEL_1;
else servoChannel=SERVO_CHANNEL_0;
ledcAttachPin(servoChannel,1);
ledcWrite(1, SERVO_HIGH);
delay(1500);
ledcWrite(1, SERVO_LOW);
delay(1500);
ledcDetachPin(servoChannel);
Serial.println("Done");
}
delay(50);
}