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 Servo MODSERIAL FastPWM
Revision 5:74962b191242, committed 2019-10-11
- Comitter:
- AnkePost
- Date:
- Fri Oct 11 11:06:43 2019 +0000
- Parent:
- 4:8ae0c82c2d60
- Commit message:
- Werkende servoaansturing, smooth met sinus
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Oct 11 09:57:47 2019 +0000
+++ b/main.cpp Fri Oct 11 11:06:43 2019 +0000
@@ -1,21 +1,21 @@
#include "mbed.h"
-#include "Servo.h"
+//#include "Servo.h"
+//#include "FastPWM.h"
+#include <math.h>
Serial pc(USBTX, USBRX);
-Servo myservo(D5);
+PwmOut myservo(D5);
int main()
{
- while(1) {
- for(int i=0; i<100; i++) {
- myservo = i/100.0;
- wait(0.01);
- pc.printf("Naar voren\n\r");
- }
- for(int i=100; i>0; i--) {
- myservo = i/100.0;
- wait(0.01);
- pc.printf("Naar achteren\n\r");
- }
- }
+ myservo.period(0.02f);
+ float t = 0;
+ while (true)
+ {
+ float ref = sin(t);
+ float pwm = 0.05 + 0.03 * ref; // maximale bereik: allebei 0.05
+ myservo.write(pwm);
+ t+=0.02; // nooit groter dan periode servomotor, zelfde geldt voor regel hieronder
+ wait(0.02);
+ }
}
\ No newline at end of file