AGH UST MBED part 2
Dependencies: LCD_DISCO_F429ZI mbed BSP_DISCO_F429ZI
stepper.cpp@4:e48aee3e8d09, 2020-05-21 (annotated)
- Committer:
- matis755
- Date:
- Thu May 21 11:03:32 2020 +0000
- Revision:
- 4:e48aee3e8d09
- Child:
- 5:3c19c3ae6286
Ready without GUI;
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 | 4:e48aee3e8d09 | 3 | enum Step{LEFT,RIGHT}; |
matis755 | 4:e48aee3e8d09 | 4 | |
matis755 | 4:e48aee3e8d09 | 5 | Stepper::Stepper() : Button(USER_BUTTON){ |
matis755 | 4:e48aee3e8d09 | 6 | } |
matis755 | 4:e48aee3e8d09 | 7 | |
matis755 | 4:e48aee3e8d09 | 8 | void Stepper::Step(enum Step eStep){ |
matis755 | 4:e48aee3e8d09 | 9 | if(eStep == LEFT){ |
matis755 | 4:e48aee3e8d09 | 10 | ucLedIdx++; |
matis755 | 4:e48aee3e8d09 | 11 | } |
matis755 | 4:e48aee3e8d09 | 12 | else if(eStep == RIGHT){ |
matis755 | 4:e48aee3e8d09 | 13 | ucLedIdx--; |
matis755 | 4:e48aee3e8d09 | 14 | } |
matis755 | 4:e48aee3e8d09 | 15 | else{} |
matis755 | 4:e48aee3e8d09 | 16 | ucLedIdx = ucLedIdx % 4; |
matis755 | 4:e48aee3e8d09 | 17 | MyLed.On(ucLedIdx); |
matis755 | 4:e48aee3e8d09 | 18 | } |
matis755 | 4:e48aee3e8d09 | 19 | |
matis755 | 4:e48aee3e8d09 | 20 | void Stepper::StepLeft(void){ |
matis755 | 4:e48aee3e8d09 | 21 | Step(LEFT); |
matis755 | 4:e48aee3e8d09 | 22 | } |
matis755 | 4:e48aee3e8d09 | 23 | |
matis755 | 4:e48aee3e8d09 | 24 | void Stepper::StepRight(void){ |
matis755 | 4:e48aee3e8d09 | 25 | Step(RIGHT); |
matis755 | 4:e48aee3e8d09 | 26 | } |
matis755 | 4:e48aee3e8d09 | 27 | |
matis755 | 4:e48aee3e8d09 | 28 | void Stepper::Callib(void) { |
matis755 | 4:e48aee3e8d09 | 29 | while(!Button) { |
matis755 | 4:e48aee3e8d09 | 30 | StepRight(); |
matis755 | 4:e48aee3e8d09 | 31 | wait(0.1); |
matis755 | 4:e48aee3e8d09 | 32 | } |
matis755 | 4:e48aee3e8d09 | 33 | } |
matis755 | 4:e48aee3e8d09 | 34 | |
matis755 | 4:e48aee3e8d09 | 35 | void Stepper::Goto(unsigned char ucDestination) { |
matis755 | 4:e48aee3e8d09 | 36 | ucDesiredPos = ucDestination; |
matis755 | 4:e48aee3e8d09 | 37 | while (ucCurrentPos > ucDesiredPos) { |
matis755 | 4:e48aee3e8d09 | 38 | StepLeft(); |
matis755 | 4:e48aee3e8d09 | 39 | ucCurrentPos --; |
matis755 | 4:e48aee3e8d09 | 40 | wait(0.2); |
matis755 | 4:e48aee3e8d09 | 41 | } |
matis755 | 4:e48aee3e8d09 | 42 | while (ucCurrentPos < ucDesiredPos) { |
matis755 | 4:e48aee3e8d09 | 43 | StepRight(); |
matis755 | 4:e48aee3e8d09 | 44 | ucCurrentPos ++; |
matis755 | 4:e48aee3e8d09 | 45 | wait(0.2); |
matis755 | 4:e48aee3e8d09 | 46 | } |
matis755 | 4:e48aee3e8d09 | 47 | } |
matis755 | 4:e48aee3e8d09 | 48 | |
matis755 | 4:e48aee3e8d09 | 49 | void Stepper::Step(unsigned char ucSteps) { |
matis755 | 4:e48aee3e8d09 | 50 | ucDesiredPos = ucCurrentPos + ucSteps; |
matis755 | 4:e48aee3e8d09 | 51 | while (ucCurrentPos < ucDesiredPos) { |
matis755 | 4:e48aee3e8d09 | 52 | StepRight(); |
matis755 | 4:e48aee3e8d09 | 53 | ucCurrentPos ++; |
matis755 | 4:e48aee3e8d09 | 54 | wait(0.2); |
matis755 | 4:e48aee3e8d09 | 55 | } |
matis755 | 4:e48aee3e8d09 | 56 | } |
matis755 | 4:e48aee3e8d09 | 57 |