mbed2 pre-final
Dependencies: LCD_DISCO_F429ZI mbed BSP_DISCO_F429ZI
servo.cpp
- Committer:
- domino5740
- Date:
- 2020-06-08
- Revision:
- 1:be03cac9fe74
- Child:
- 2:7dc265489818
File content as of revision 1:be03cac9fe74:
#include "servo.h" Servo myServo; Servo::Servo(unsigned int uiServoFrequency) { LedInit(); sServo.eState = CALLIB; Timer0Interrupts_Init((1000000/uiServoFrequency), &ServoAutomat); while(sServo.eState != IDLE) {} } void ServoGoTo(unsigned int uiPosition) { sServo.uiDesiredPosition = uiPosition; sServo.eState = IN_PROGRESS; while(sServo.eState != IDLE) {} } void ServoCallib() { sServo.eState = CALLIB; while(sServo.eState != IDLE) {} } void Servo::Automat() { switch(myServo::eState) { case IN_PROGRESS: if(uiCurrentPosition < uiDesiredPosition) { LedStepRight(); uiCurrentPosition++; } else if(uiCurrentPosition > uiDesiredPosition){ LedStepLeft(); uiCurrentPosition--; } else { eState = IDLE; } break; case IDLE: if (uiCurrentPosition != uiDesiredPosition) { eState = IN_PROGRESS; } else {} break; case CALLIB: if(eReadDetector() == ACTIVE) { eState = IDLE; uiCurrentPosition = 0; uiDesiredPosition = 0; } else { LedStepLeft(); } break; } } enum DetectorState eReadDetector() { if ((IO0PIN & DETECTOR_bm) == 0) { return ACTIVE; } else { return INACTIVE; } }