Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
sm_servo.cpp
- Committer:
- GaspardD
- Date:
- 2019-09-29
- Revision:
- 4:efa207509f63
- Parent:
- 3:1b7eb426247e
- Child:
- 6:ab9f3695633f
File content as of revision 4:efa207509f63:
#include "sm_servo.h" PwmOut pwm_Servo(PE_9); E_STATE_SERVO e_stateServo; bool directionCheck = false; int pulsewidth = SERVO_PULSE_MAX_US; void init_sm_servo() { e_stateServo = SERVO_INIT; } void update_sm_servo() { E_STATE_SERVO next_state = e_stateServo; switch(e_stateServo) { case SERVO_INIT: if(directionCheck) { next_state = SERVO_COMMAND; } break; case SERVO_COMMAND: break; default: break; } e_stateServo = next_state; return; } void output_sm_servo() { switch(e_stateServo) { case SERVO_INIT: wait(1); pc.printf("init servo with pulse %d us\r\n",SERVO_PULSE_MIDDLE_US); pwm_Servo.period_ms(SERVO_PERIOD_DURATION_MS); pwm_Servo.pulsewidth_us(SERVO_PULSE_MIDDLE_US); directionCheck = true; break; case SERVO_COMMAND: /* if(pulsewidth < SERVO_PULSE_MAX_US && directionCheck) { pulsewidth += 1; if (pulsewidth >= SERVO_PULSE_MAX_US) { directionCheck = false; } } else if (pulsewidth > SERVO_PULSE_MIN_US && !directionCheck) { pulsewidth -= 1; if (pulsewidth <= SERVO_PULSE_MIN_US) { directionCheck = true; } } pc.printf("send pulse %d to servo\r\n",pulsewidth); */ pwm_Servo.pulsewidth_us(pulsewidth); break; default: break; } return; }