For some reason it does something now. Not really sure what made it work. It did however change the frequency to 200. Somewhere I read that that was necessary for ESP32. It seems to be working.
However, I can not position it the way I want and need it. It extracts not to the complete length of the rod (it should extract 12cm, it does about 7cm) and when retracting it keeps spinning as though it expects to retract more (that is in accordance to the not fully extending. So, anyone an idea? Something about the initial zero position and how to set this up?
Below the current 'simple' code.
#include <M5Atom.h>
const int8_t linActPin1 = 33;
const int8_t linActPin2 = 23;
const int linActChannel1 = 1;
const int linActChannel2 = 2;
const int linActFreq = 200;
const int linActResolution = 8;
uint8_t method;
void setup() {
Serial.println();
ledcSetup(linActChannel1, linActFreq, linActResolution);
ledcAttachPin(linActPin1, linActChannel1);
ledcSetup(linActChannel2, linActFreq, linActResolution);
ledcAttachPin(linActPin2, linActChannel2);
}
void setServoPos(int8_t pos) {
ledcWrite(linActChannel1, pos);
ledcWrite(linActChannel2, pos);
}
void loop() {
method = 1;
Serial.print("O");
for (int posDegrees = 0; posDegrees <= 180; posDegrees++) {
setServoPos(posDegrees);
delay(50);
}
Serial.print("I");
for (int posDegrees = 180; posDegrees >= 0; posDegrees--) {
setServoPos(posDegrees);
delay(20);
}
Serial.print("-");
}