Finalny program mbed2
Dependencies: LCD_DISCO_F429ZI mbed TS_DISCO_F429ZI BSP_DISCO_F429ZI
servo.cpp@0:33ff53112cc9, 2020-06-09 (annotated)
- Committer:
- azmuth_sd
- Date:
- Tue Jun 09 08:24:40 2020 +0000
- Revision:
- 0:33ff53112cc9
Ostatni program drugiej czesci mbed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
azmuth_sd | 0:33ff53112cc9 | 1 | #include "servo.h" |
azmuth_sd | 0:33ff53112cc9 | 2 | |
azmuth_sd | 0:33ff53112cc9 | 3 | InterruptIn user_button(USER_BUTTON); |
azmuth_sd | 0:33ff53112cc9 | 4 | |
azmuth_sd | 0:33ff53112cc9 | 5 | void Servo::Automat(){ |
azmuth_sd | 0:33ff53112cc9 | 6 | |
azmuth_sd | 0:33ff53112cc9 | 7 | switch(eState){ |
azmuth_sd | 0:33ff53112cc9 | 8 | |
azmuth_sd | 0:33ff53112cc9 | 9 | case CALLIB: |
azmuth_sd | 0:33ff53112cc9 | 10 | if(user_button == 0){ |
azmuth_sd | 0:33ff53112cc9 | 11 | myLed.StepLeft(); |
azmuth_sd | 0:33ff53112cc9 | 12 | } |
azmuth_sd | 0:33ff53112cc9 | 13 | else{ |
azmuth_sd | 0:33ff53112cc9 | 14 | uiCurrentPosition = 0; |
azmuth_sd | 0:33ff53112cc9 | 15 | uiDesiredPosition = 0; |
azmuth_sd | 0:33ff53112cc9 | 16 | eState = IDLE; |
azmuth_sd | 0:33ff53112cc9 | 17 | } |
azmuth_sd | 0:33ff53112cc9 | 18 | break; |
azmuth_sd | 0:33ff53112cc9 | 19 | |
azmuth_sd | 0:33ff53112cc9 | 20 | case IDLE: |
azmuth_sd | 0:33ff53112cc9 | 21 | |
azmuth_sd | 0:33ff53112cc9 | 22 | if(uiCurrentPosition != uiDesiredPosition){ |
azmuth_sd | 0:33ff53112cc9 | 23 | eState = IN_PROGRESS; |
azmuth_sd | 0:33ff53112cc9 | 24 | } |
azmuth_sd | 0:33ff53112cc9 | 25 | break; |
azmuth_sd | 0:33ff53112cc9 | 26 | |
azmuth_sd | 0:33ff53112cc9 | 27 | case IN_PROGRESS: |
azmuth_sd | 0:33ff53112cc9 | 28 | if(uiCurrentPosition < uiDesiredPosition){ |
azmuth_sd | 0:33ff53112cc9 | 29 | uiCurrentPosition++; |
azmuth_sd | 0:33ff53112cc9 | 30 | myLed.StepRight(); |
azmuth_sd | 0:33ff53112cc9 | 31 | } |
azmuth_sd | 0:33ff53112cc9 | 32 | else if(uiCurrentPosition > uiDesiredPosition){ |
azmuth_sd | 0:33ff53112cc9 | 33 | uiCurrentPosition--; |
azmuth_sd | 0:33ff53112cc9 | 34 | myLed.StepLeft(); |
azmuth_sd | 0:33ff53112cc9 | 35 | } |
azmuth_sd | 0:33ff53112cc9 | 36 | else{ |
azmuth_sd | 0:33ff53112cc9 | 37 | eState = IDLE; |
azmuth_sd | 0:33ff53112cc9 | 38 | } |
azmuth_sd | 0:33ff53112cc9 | 39 | break; |
azmuth_sd | 0:33ff53112cc9 | 40 | } |
azmuth_sd | 0:33ff53112cc9 | 41 | } |
azmuth_sd | 0:33ff53112cc9 | 42 | |
azmuth_sd | 0:33ff53112cc9 | 43 | void Servo::Callib(void){ |
azmuth_sd | 0:33ff53112cc9 | 44 | |
azmuth_sd | 0:33ff53112cc9 | 45 | eState = CALLIB; |
azmuth_sd | 0:33ff53112cc9 | 46 | while(eState != IDLE){ |
azmuth_sd | 0:33ff53112cc9 | 47 | wait_ms(1); |
azmuth_sd | 0:33ff53112cc9 | 48 | } |
azmuth_sd | 0:33ff53112cc9 | 49 | } |
azmuth_sd | 0:33ff53112cc9 | 50 | |
azmuth_sd | 0:33ff53112cc9 | 51 | void Servo::GoTo(unsigned int uiPosition){ |
azmuth_sd | 0:33ff53112cc9 | 52 | |
azmuth_sd | 0:33ff53112cc9 | 53 | uiDesiredPosition = uiPosition; |
azmuth_sd | 0:33ff53112cc9 | 54 | eState = IN_PROGRESS; |
azmuth_sd | 0:33ff53112cc9 | 55 | while(eState != IDLE){ |
azmuth_sd | 0:33ff53112cc9 | 56 | wait_ms(1); |
azmuth_sd | 0:33ff53112cc9 | 57 | } |
azmuth_sd | 0:33ff53112cc9 | 58 | } |
azmuth_sd | 0:33ff53112cc9 | 59 | |
azmuth_sd | 0:33ff53112cc9 | 60 | void Servo::StepRight(unsigned int uiSteps){ |
azmuth_sd | 0:33ff53112cc9 | 61 | |
azmuth_sd | 0:33ff53112cc9 | 62 | uiDesiredPosition += uiSteps; |
azmuth_sd | 0:33ff53112cc9 | 63 | eState = IN_PROGRESS; |
azmuth_sd | 0:33ff53112cc9 | 64 | while(eState != IDLE){ |
azmuth_sd | 0:33ff53112cc9 | 65 | wait_ms(1); |
azmuth_sd | 0:33ff53112cc9 | 66 | } |
azmuth_sd | 0:33ff53112cc9 | 67 | } |