舵机测试完成
This commit is contained in:
parent
6e423bb12f
commit
e9d088ab28
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"*.tcc": "cpp"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
void servo_init();
|
||||||
|
void servo_loop();
|
|
@ -8,7 +8,9 @@
|
||||||
; Please visit documentation for the other options and examples
|
; Please visit documentation for the other options and examples
|
||||||
; https://docs.platformio.org/page/projectconf.html
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
[env:esp_wroom_02]
|
[env:esp32doit-devkit-v1]
|
||||||
platform = espressif8266
|
platform = espressif32
|
||||||
board = esp_wroom_02
|
board = esp32doit-devkit-v1
|
||||||
framework = arduino
|
framework = arduino
|
||||||
|
lib_deps = madhephaestus/ESP32Servo@^0.12.0
|
||||||
|
monitor_speed = 115200
|
|
@ -1,9 +1,12 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include <servo.h>
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// put your setup code here, to run once:
|
Serial.begin(115200);
|
||||||
|
servo_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// put your main code here, to run repeatedly:
|
servo_loop();
|
||||||
|
delay(1000);
|
||||||
}
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <ESP32Servo.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
Loading…
Reference in New Issue