Hello, i have school project to make servo motor controlled with potentiometer, and i did that, but now i need to add in this program command with this function: if sevo motor is not moving for some time, then he needs to automaticaly turn to 90 degrees, i dont know how to write command with this function. Please help.
Here is my code who only controls servo with potentiometer:
If I understand your problem correctly you need to record the time (millis() ) whenever the potentiometer value changes. Then you can do something else if there is a long gap after the most recent move.
Code like this should do the job
btnVal = digitalRead(btnPin);
if (btnVal == HIGH) { // assumes btn is LOW when pressed
lastBtnPressMillis = millis(); // btn not pressed so reset clock
}
if (millis() - lastBtnPressMillis > = interval) {
// button has been pressed for longer than interval
}
A hobby servo is more correctly a small self-contained servomechanism. OK, that means it contains
a small servo motor I suppose, but I thought for a moment you had a more ambitious project there!