Hi !! Now i have changed the code and the change to function 2 worked almost perfect ! When function 2 is activated the stepper moves to:
stepper1.write(compassAngle1);
i want stepper1.write(compassAngle1) to write the compassAngle1 value every 200ms because the compassAngle1 value changes when the mount is rotated.
What is the best solution to that ?
switch ( myButtons.clicked(0) ) {
case NOCLICK:
; // do nothing
break;
case DOUBLECLICK:
Serial.println( "Return RP" );
stepper1.setSpeedSteps( 20000 ); // Speed when moving home
stepper1.write(0);
function = 3;
break;
case SINGLECLICK:
Serial.println( "Set function 2 Spotlock" );
stepper1.setSpeedSteps( 20000 ); // Speed when moving home
mountAngleSpotlock = mountAngle; // Save spotlock activated angle
stepper1.write(compassAngle1);
function = 2;
break;
}
if (joyTimer.tick() ) {
// read joystick and set stepper speed accordingly
joyLR = analogRead(joyLRPin);
// if the joystic is not in the middle ===> its activ
bool joyActive = !(joyLR > joyLimits[1] && joyLR < joyLimits[2]);
switch ( function ) {
case 1: // mode 1 - joystick control
if ( !joyActive ) // neutral area
{
digitalWrite(ledPin, HIGH);
stepper1.rotate(0 ); // stop stepper if joystick in the middle
}
else
{ // move the motor in desired direction
digitalWrite(ledPin, LOW);
if ( joyLR >= joyLimits[2] ) {
// move towards max angle
motorSpeed = map ( joyLR , joyLimits[2], joyLimits[3] , minSpeed, maxSpeed ); // Values may be adjusted to the joystick
stepper1.setSpeedSteps( motorSpeed * 10 );
stepper1.write( maxAngle );
} else {
// move towards min angle
motorSpeed = map ( joyLR , joyLimits[1], joyLimits[0] , minSpeed, maxSpeed ); // Values may be adjusted to the joystick
stepper1.setSpeedSteps( motorSpeed * 10 );
stepper1.write( -maxAngle );
}
}
break;
case 2: // // Move to angle set by compass for testing "compassAngle1",
// // switch back to joystick control if position reached or joystick is active
// if ( !stepper1.moving() || joyActive ) function = 1;
if ( joyActive || holdTimer.expired() ) function = 1;
if ( !stepper1.moving() && !holdTimer.running() ) {
holdTimer.setTime( 6000 );
}
break;
case 3: // return to reference point,
// switch back to joystick control if reached or joystick is active
if ( !stepper1.moving() || joyActive ) function = 1;
break;
}
}
Best Regards
Andreas