a
Dependencies: LCD_DISCO_F429ZI mbed BSP_DISCO_F429ZI
stepper.cpp@6:06ff453bb16e, 2020-05-22 (annotated)
- Committer:
- matis755
- Date:
- Fri May 22 07:30:59 2020 +0000
- Revision:
- 6:06ff453bb16e
- Parent:
- 5:3c19c3ae6286
Use standard C functions
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
matis755 | 4:e48aee3e8d09 | 1 | #include "stepper.h" |
matis755 | 4:e48aee3e8d09 | 2 | |
matis755 | 5:3c19c3ae6286 | 3 | #define TDELAY 0.2 |
matis755 | 5:3c19c3ae6286 | 4 | |
matis755 | 4:e48aee3e8d09 | 5 | enum Step{LEFT,RIGHT}; |
matis755 | 4:e48aee3e8d09 | 6 | |
matis755 | 5:3c19c3ae6286 | 7 | Stepper::Stepper(void) : Button(USER_BUTTON){ |
matis755 | 4:e48aee3e8d09 | 8 | } |
matis755 | 4:e48aee3e8d09 | 9 | |
matis755 | 4:e48aee3e8d09 | 10 | void Stepper::Step(enum Step eStep){ |
matis755 | 4:e48aee3e8d09 | 11 | if(eStep == LEFT){ |
matis755 | 5:3c19c3ae6286 | 12 | ucLedIdx --; |
matis755 | 4:e48aee3e8d09 | 13 | } |
matis755 | 4:e48aee3e8d09 | 14 | else if(eStep == RIGHT){ |
matis755 | 5:3c19c3ae6286 | 15 | ucLedIdx ++; |
matis755 | 4:e48aee3e8d09 | 16 | } |
matis755 | 4:e48aee3e8d09 | 17 | else{} |
matis755 | 4:e48aee3e8d09 | 18 | ucLedIdx = ucLedIdx % 4; |
matis755 | 4:e48aee3e8d09 | 19 | MyLed.On(ucLedIdx); |
matis755 | 5:3c19c3ae6286 | 20 | MyGui.RefreshLeds(ucLedIdx); |
matis755 | 5:3c19c3ae6286 | 21 | MyGui.RefreshTop(ucCurrentPos); |
matis755 | 4:e48aee3e8d09 | 22 | } |
matis755 | 4:e48aee3e8d09 | 23 | |
matis755 | 4:e48aee3e8d09 | 24 | void Stepper::StepLeft(void){ |
matis755 | 5:3c19c3ae6286 | 25 | ucCurrentPos --; |
matis755 | 4:e48aee3e8d09 | 26 | Step(LEFT); |
matis755 | 4:e48aee3e8d09 | 27 | } |
matis755 | 4:e48aee3e8d09 | 28 | |
matis755 | 4:e48aee3e8d09 | 29 | void Stepper::StepRight(void){ |
matis755 | 5:3c19c3ae6286 | 30 | ucCurrentPos ++; |
matis755 | 4:e48aee3e8d09 | 31 | Step(RIGHT); |
matis755 | 4:e48aee3e8d09 | 32 | } |
matis755 | 4:e48aee3e8d09 | 33 | |
matis755 | 4:e48aee3e8d09 | 34 | void Stepper::Callib(void) { |
matis755 | 4:e48aee3e8d09 | 35 | while(!Button) { |
matis755 | 4:e48aee3e8d09 | 36 | StepRight(); |
matis755 | 5:3c19c3ae6286 | 37 | wait(TDELAY); |
matis755 | 4:e48aee3e8d09 | 38 | } |
matis755 | 5:3c19c3ae6286 | 39 | MyGui.SetRelAngle(ucCurrentPos); |
matis755 | 5:3c19c3ae6286 | 40 | ucCurrentPos = 0; |
matis755 | 4:e48aee3e8d09 | 41 | } |
matis755 | 4:e48aee3e8d09 | 42 | |
matis755 | 4:e48aee3e8d09 | 43 | void Stepper::Goto(unsigned char ucDestination) { |
matis755 | 4:e48aee3e8d09 | 44 | ucDesiredPos = ucDestination; |
matis755 | 4:e48aee3e8d09 | 45 | while (ucCurrentPos > ucDesiredPos) { |
matis755 | 4:e48aee3e8d09 | 46 | StepLeft(); |
matis755 | 5:3c19c3ae6286 | 47 | wait(TDELAY); |
matis755 | 4:e48aee3e8d09 | 48 | } |
matis755 | 4:e48aee3e8d09 | 49 | while (ucCurrentPos < ucDesiredPos) { |
matis755 | 4:e48aee3e8d09 | 50 | StepRight(); |
matis755 | 5:3c19c3ae6286 | 51 | wait(TDELAY); |
matis755 | 4:e48aee3e8d09 | 52 | } |
matis755 | 4:e48aee3e8d09 | 53 | } |
matis755 | 4:e48aee3e8d09 | 54 | |
matis755 | 4:e48aee3e8d09 | 55 | void Stepper::Step(unsigned char ucSteps) { |
matis755 | 4:e48aee3e8d09 | 56 | ucDesiredPos = ucCurrentPos + ucSteps; |
matis755 | 4:e48aee3e8d09 | 57 | while (ucCurrentPos < ucDesiredPos) { |
matis755 | 4:e48aee3e8d09 | 58 | StepRight(); |
matis755 | 5:3c19c3ae6286 | 59 | wait(TDELAY); |
matis755 | 4:e48aee3e8d09 | 60 | } |
matis755 | 4:e48aee3e8d09 | 61 | } |