Simon Dziadon / Mbed 2 deprecated mbed_cz2_5_test

Dependencies:   LCD_DISCO_F429ZI mbed TS_DISCO_F429ZI BSP_DISCO_F429ZI

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers servo.cpp Source File

servo.cpp

00001 #include "servo.h"
00002 
00003 InterruptIn user_button(USER_BUTTON);
00004 
00005 void Servo::Automat(){
00006 
00007     switch(eState){
00008             
00009         case CALLIB:
00010             if(user_button == 0){
00011                 myLed.StepLeft(); 
00012             }
00013             else{  
00014                 uiCurrentPosition = 0;
00015                 uiDesiredPosition = 0;
00016                 eState = IDLE;
00017             }
00018             break;
00019             
00020         case IDLE:
00021 
00022             if(uiCurrentPosition != uiDesiredPosition){
00023                 eState = IN_PROGRESS; 
00024             }
00025             break;
00026             
00027         case IN_PROGRESS:
00028             if(uiCurrentPosition < uiDesiredPosition){
00029                 uiCurrentPosition++;
00030                 myLed.StepRight();
00031             }
00032             else if(uiCurrentPosition > uiDesiredPosition){
00033                 uiCurrentPosition--;
00034                 myLed.StepLeft();
00035             }
00036             else{
00037                 eState = IDLE;
00038             }
00039             break;
00040     }
00041 }
00042 
00043 void Servo::Callib(void){
00044     
00045     eState = CALLIB;
00046     while(eState != IDLE){ 
00047         wait_ms(1);
00048     }
00049 }
00050 
00051 void Servo::GoTo(unsigned int uiPosition){
00052     
00053     uiDesiredPosition = uiPosition;
00054     eState = IN_PROGRESS;
00055     while(eState != IDLE){ 
00056         wait_ms(1);
00057     }
00058 }
00059 
00060 void Servo::StepRight(unsigned int uiSteps){
00061     
00062     uiDesiredPosition += uiSteps;
00063     eState = IN_PROGRESS;
00064     while(eState != IDLE){
00065         wait_ms(1);
00066     }
00067 }