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.
Dependencies: mbed-STM32F103C8T6 mbed
Diff: main.cpp
- Revision:
- 5:e86eda00ef3f
- Parent:
- 4:2196462a17f5
- Child:
- 6:c8265ecd2d1f
--- a/main.cpp Tue Apr 10 20:36:08 2018 +0000
+++ b/main.cpp Wed Apr 18 12:24:46 2018 +0000
@@ -1,26 +1,29 @@
#include "mbed.h"
#include "stm32f103c8t6.h"
#define val 0.05 // percents in step / 100
+#define pi 3.1415
-PwmOut Servo (PC_13);
+PwmOut Servo (PA_8);
+DigitalOut myled(PC_13);
Ticker timer;
-double f;
-int i = 0;
+double f = 0; //first period
+double i = 0;
void sinus (){
- f = (sin((double)i) + 1.0) / 2 + 1; //1..2
- i++;
- if (i > 360) i = 0;
- Servo = (float)f * val;
+ Servo = (float)f * val; // duty-cycle, perсents 0..1; посчитанное значение вставится в следующее прерывание
+ i += 0.1;
+ if (i > 2) i = 0;
+ f = (sin(i * pi) + 1.0) / 2 + 1; //1..2
}
int main() {
confSysClock();
Servo.period_ms(20);
- timer.attach(&sinus, 1 / 360); //sine period, sec
+ timer.attach(&sinus, val); //sine period, sec
while(1) {
- // duty-cycle, perсents 0..1;
+ myled = !myled;
+ wait(0.5);
}
}