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

Dependencies:   mbed-STM32F103C8T6 mbed

main.cpp

Committer:
RuslanUrya
Date:
2018-04-09
Revision:
1:b8fb21d3836e
Parent:
0:fb723d2f5d7e
Child:
2:3f9a695cde1c

File content as of revision 1:b8fb21d3836e:

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

PwmOut Servo (PA_8);
Timeout timer;


double f, i = 0;

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

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