test
main.cpp
- Committer:
- gorazdko
- Date:
- 2019-06-02
- Revision:
- 44:50aa0a0d1222
- Parent:
- 43:bda92a299378
- Child:
- 45:200518382f20
File content as of revision 44:50aa0a0d1222:
#include "mbed.h"
//Program to 'sweep' test a 'standard RC type servo
//Define some parameters using compiler directive '#define'
//Check Servo DATA if 0.75ms to 2.25ms then use min=750 and max=2250
//NB be values in microseconds (Following are generic values)
#define MID 1500
#define MIN 544
#define MAX 2400
#define STEP 50
//Time delay between steps in milliseconds
#define TIME 20 //100
#define DELTA 50
DigitalOut myLed(LED1);
DigitalIn myButton(USER_BUTTON);
PwmOut myServo(D3);
void motor_on(void)
{
//myServo.period_ms(20);
myServo.pulsewidth_us(MID); //NB in microseconds
}
void motor_off(void)
{
myServo.pulsewidth_us(MIN+2*DELTA); //NB in microseconds
}
int main() {
wait(3); // if (myButton)
while (1)
{
/*
for (int i=0; i<50*3; i++)
{
//myServo.period_ms(20);
myServo.pulsewidth_us(MIN); //NB in microseconds
wait_ms(TIME);
}
for (int i=0; i<50*3; i++)
{
//myServo.period_ms(20);
myServo.pulsewidth_us(MID); //NB in microseconds
wait_ms(TIME);
}
*/
while (myButton)
{
myServo.pulsewidth_us(MIN); //NB in microseconds
wait_ms(TIME);
}
myServo.pulsewidth_us(MID); //NB in microseconds
wait_ms(TIME);
}
/*
while(true) {
for (int i=MIN;i<=MAX;i+=STEP){
myServo.pulsewidth_us(i);
wait_ms(TIME);
}
for (int i=MAX;i>=MIN;i-=STEP){
myServo.pulsewidth_us(i);
wait_ms(TIME);
}
*/
}