Hello, im looking for some help here, im new to arduino and programming.I found this thread very useful and also Robins2 code for "Excavator". i just edit code to work like i want - normal movement of servo with joystick, but now i want to add this functionality to my code - holding position of servo arm while joystick get back to neutral. Original code of Robin2 works perfect but i dont know to implement it to my code. Here is my piece or art:
#include <Servo.h>
Servo servo[1]; // create servo object to control a servo
int potPin[1]={A0};
int potValue;
int servodt=10;
int servoPin[1]={9};
int pushbutton=1;
int servoValue[1]={1472};
void setup() {
for (byte n = 0; n < 1; n++){
servo[n].attach(servoPin[n]);
}
}
void loop() {
readPotentiometers();
moveServos();
delay(servodt);
}
void readPotentiometers(){
for (byte n = 0; n < 1; n++){
potValue = analogRead(potPin[1]);
potValue = map(potValue, 0, 1023, 544, 2400);
if (potValue >= 1372 && potValue <= 1572 ) {
servoValue[1] = 1472;
}
if (potValue <= 1372 ) {
servoValue[1] = potValue + 100;
}
if (potValue >= 1572 ) {
servoValue[1] = potValue - 100;
}
if (pushbutton = 1 && potValue < 1372) {
}
}
}
void moveServos() {
for (byte n = 0; n < 1; n++) {
servo[n].writeMicroseconds(servoValue[1]);
}
}
if (pushbutton = 1 && potValue < 1372) .... here i want to add code for hold position functionality, but i cannot figure it out how.
Can someone help me?