AGH UST MBED part 2
Dependencies: LCD_DISCO_F429ZI mbed BSP_DISCO_F429ZI
Diff: stepper.cpp
- Revision:
- 5:3c19c3ae6286
- Parent:
- 4:e48aee3e8d09
diff -r e48aee3e8d09 -r 3c19c3ae6286 stepper.cpp --- a/stepper.cpp Thu May 21 11:03:32 2020 +0000 +++ b/stepper.cpp Fri May 22 07:21:44 2020 +0000 @@ -1,48 +1,54 @@ #include "stepper.h" +#define TDELAY 0.2 + enum Step{LEFT,RIGHT}; -Stepper::Stepper() : Button(USER_BUTTON){ +Stepper::Stepper(void) : Button(USER_BUTTON){ } void Stepper::Step(enum Step eStep){ if(eStep == LEFT){ - ucLedIdx++; + ucLedIdx --; } else if(eStep == RIGHT){ - ucLedIdx--; + ucLedIdx ++; } else{} ucLedIdx = ucLedIdx % 4; MyLed.On(ucLedIdx); + MyGui.RefreshLeds(ucLedIdx); + MyGui.RefreshTop(ucCurrentPos); } void Stepper::StepLeft(void){ + ucCurrentPos --; Step(LEFT); } void Stepper::StepRight(void){ + ucCurrentPos ++; Step(RIGHT); } void Stepper::Callib(void) { while(!Button) { StepRight(); - wait(0.1); + wait(TDELAY); } + MyGui.SetRelAngle(ucCurrentPos); + ucCurrentPos = 0; } void Stepper::Goto(unsigned char ucDestination) { ucDesiredPos = ucDestination; while (ucCurrentPos > ucDesiredPos) { StepLeft(); - ucCurrentPos --; - wait(0.2); + wait(TDELAY); } while (ucCurrentPos < ucDesiredPos) { StepRight(); - ucCurrentPos ++; - wait(0.2); + wait(TDELAY); } } @@ -50,8 +56,6 @@ ucDesiredPos = ucCurrentPos + ucSteps; while (ucCurrentPos < ucDesiredPos) { StepRight(); - ucCurrentPos ++; - wait(0.2); + wait(TDELAY); } } -