Руслан Урядинский / Mbed 2 deprecated Servo_move_sin

Dependencies:   mbed-STM32F103C8T6 mbed

main.cpp

Committer:
RuslanUrya
Date:
2018-04-10
Revision:
3:ca6028700d1a
Parent:
2:3f9a695cde1c
Child:
4:2196462a17f5

File content as of revision 3:ca6028700d1a:

#include "mbed.h"
#include "stm32f103c8t6.h"
#define val 0.05 // percents in step / 100

PwmOut Servo (PA_8);
Timeout timer;


double f;
int i = 0;

void sinus (){
    f = (sin((double)i) + 1.0) / 2 + 1; //1..2
    i += 1;
    if (i > 360) i = 0;
    Servo = (float)f * val; // duty-cycle, perсents 0..1;
}

int main() {
    confSysClock();
    Servo.period_ms(20);
    while(1) {
        timer.attach(&sinus, 1 / 360); //sine period, sec
    }
}