Added a rampdown section to the speed.
This commit is contained in:
parent
87b1cb9acd
commit
33ddb0a4e9
1 changed files with 16 additions and 3 deletions
19
src/main.c
19
src/main.c
|
@ -142,11 +142,23 @@ void MotorMoveTo(uint8_t target) {
|
|||
|
||||
uint8_t on_delay = ReadSpeed();
|
||||
uint8_t pos = ReadFader();
|
||||
uint8_t delta = diff(target, pos);
|
||||
uint8_t idx = 0;
|
||||
|
||||
while (diff(target, pos) > 4) {
|
||||
on_delay = ReadSpeed();
|
||||
while (delta > 0) {
|
||||
pos = ReadFader();
|
||||
delta = diff(target, pos);
|
||||
|
||||
//Impliment a ramp down when near target position.
|
||||
if(delta <= 6){
|
||||
//Ignore speed value and set for 50% speed.
|
||||
on_delay = 127;
|
||||
}
|
||||
//Otherwise use the speed input.
|
||||
else{
|
||||
on_delay = ReadSpeed();
|
||||
}
|
||||
|
||||
if (target > pos) {
|
||||
MotorMove(1);
|
||||
} else {
|
||||
|
@ -161,6 +173,7 @@ void MotorMoveTo(uint8_t target) {
|
|||
for (; idx < 255; idx++) {
|
||||
_delay_us(MOTOR_PULSE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -271,7 +284,7 @@ static void UpdateButtonOutput(btn_state *b) {
|
|||
if (b->is_active) {
|
||||
|
||||
/*If already in saved position then go back to original pos.*/
|
||||
if(diff(MotorGetSavedPos((uint8_t *)POSITION1_ADR), ReadFader()) < 4){
|
||||
if(diff(MotorGetSavedPos((uint8_t *)POSITION1_ADR), ReadFader()) <= 2){
|
||||
MotorMoveTo(MotorGetSavedPos((uint8_t *)POSITION2_ADR));
|
||||
}
|
||||
else{
|
||||
|
|
Loading…
Add table
Reference in a new issue