diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..930ff05 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "*.tcc": "cpp" + } +} \ No newline at end of file diff --git a/include/servo.h b/include/servo.h new file mode 100644 index 0000000..c05ba55 --- /dev/null +++ b/include/servo.h @@ -0,0 +1,2 @@ +void servo_init(); +void servo_loop(); \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 4952359..11be3b8 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,7 +8,9 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html -[env:esp_wroom_02] -platform = espressif8266 -board = esp_wroom_02 +[env:esp32doit-devkit-v1] +platform = espressif32 +board = esp32doit-devkit-v1 framework = arduino +lib_deps = madhephaestus/ESP32Servo@^0.12.0 +monitor_speed = 115200 \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 58b344c..10ab05c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,9 +1,12 @@ #include +#include void setup() { - // put your setup code here, to run once: + Serial.begin(115200); + servo_init(); } void loop() { - // put your main code here, to run repeatedly: + servo_loop(); + delay(1000); } \ No newline at end of file diff --git a/src/servo.cpp b/src/servo.cpp new file mode 100644 index 0000000..f6400b7 --- /dev/null +++ b/src/servo.cpp @@ -0,0 +1,45 @@ +#include +#include + +Servo servo[8]; +ESP32PWM pwm; + +int servoPin[8] = {13,12,14,26,25,33,32,15}; + +int minUs = 500; +int maxUs = 2500; + +int pos = 0; + +void servo_init() { + for (int i = 0; i < 8; i++) { + ESP32PWM::allocateTimer(i); + servo[i].setPeriodHertz(50); + } +} + +void servo_loop() { + for (int i = 0; i < 8; i++) { + servo[i].attach(servoPin[i], minUs, maxUs); + } + pwm.attachPin(27, 10000); + +// for (int j = 0; j < 8; j++) { +// for (pos = 0; pos <= 180; pos += 1) { +// servo[j].write(pos); +// Serial.println(pos); +// delay(5); +// } +// for (pos = 0; pos <= 180; pos += 1) { +// servo[j].write(180 - pos); +// Serial.println(180 - pos); +// delay(5); +// } +// } + + for (int i = 0; i < 8; i++) { + servo[i].detach(); + } + pwm.detachPin(27); + delay(500); +} \ No newline at end of file