Script om de servomotor uit te proberen

Dependencies:   mbed mbed

Committer:
lisa96m
Date:
Thu Oct 20 10:08:47 2016 +0000
Revision:
1:acd79b94fe6a
Parent:
0:ebffc70ade24
Try out servo;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lisa96m 0:ebffc70ade24 1 #include "mbed.h"
lisa96m 0:ebffc70ade24 2
lisa96m 0:ebffc70ade24 3 #define SERIAL_BAUD 115200
lisa96m 0:ebffc70ade24 4
lisa96m 0:ebffc70ade24 5 Serial pc(USBTX, USBRX);
lisa96m 0:ebffc70ade24 6
lisa96m 0:ebffc70ade24 7 PwmOut servo(A4);
lisa96m 1:acd79b94fe6a 8 volatile double x = 0;
lisa96m 0:ebffc70ade24 9
lisa96m 0:ebffc70ade24 10 void loop()
lisa96m 0:ebffc70ade24 11 {
lisa96m 0:ebffc70ade24 12 double y = sin(x);
lisa96m 0:ebffc70ade24 13 {
lisa96m 1:acd79b94fe6a 14 x = x+0.2;
lisa96m 0:ebffc70ade24 15 }
lisa96m 0:ebffc70ade24 16 servo = abs(y);
lisa96m 0:ebffc70ade24 17 pc.printf("grootte van sinus is %f.\r\n", abs(y));
lisa96m 1:acd79b94fe6a 18 pc.printf("grootte van x is %f.\r\n", x);
lisa96m 0:ebffc70ade24 19 }
lisa96m 0:ebffc70ade24 20
lisa96m 0:ebffc70ade24 21 int main()
lisa96m 0:ebffc70ade24 22 {
lisa96m 0:ebffc70ade24 23 pc.baud(SERIAL_BAUD);
lisa96m 1:acd79b94fe6a 24 servo.period(0.020);
lisa96m 0:ebffc70ade24 25 while(true) {
lisa96m 0:ebffc70ade24 26 loop();
lisa96m 1:acd79b94fe6a 27 wait(2);
lisa96m 0:ebffc70ade24 28 }
lisa96m 0:ebffc70ade24 29 }