PWM motor controler. Serial DAQ float 0 upto 1

Dependencies:   mbed

Committer:
kanatronics
Date:
Fri Jun 24 15:03:59 2016 +0000
Revision:
1:a3dae8744a7d
Parent:
0:d26101f286c4
Changed formatings

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kanatronics 0:d26101f286c4 1 /*Kamil Kanas
kanatronics 0:d26101f286c4 2 Nucleo PWM to Serial motor controller
kanatronics 1:a3dae8744a7d 3 Rev 1.1
kanatronics 0:d26101f286c4 4 */
kanatronics 0:d26101f286c4 5
kanatronics 0:d26101f286c4 6 #include "mbed.h"
kanatronics 1:a3dae8744a7d 7
kanatronics 0:d26101f286c4 8 Serial pc(USBTX,USBRX);
kanatronics 0:d26101f286c4 9 PwmOut led(D13);
kanatronics 0:d26101f286c4 10
kanatronics 1:a3dae8744a7d 11 float pwmOut; //PWM port
kanatronics 0:d26101f286c4 12 char buffer[16];
kanatronics 0:d26101f286c4 13
kanatronics 0:d26101f286c4 14 int main() {
kanatronics 1:a3dae8744a7d 15 pc.baud(115200); //Set baud rate
kanatronics 0:d26101f286c4 16
kanatronics 1:a3dae8744a7d 17 while (1){
kanatronics 0:d26101f286c4 18 led=pwmOut;
kanatronics 1:a3dae8744a7d 19 while(true){
kanatronics 1:a3dae8744a7d 20 if(pc.readable()) { //if data in the ring buffer
kanatronics 0:d26101f286c4 21 pc.gets(buffer, 8);
kanatronics 0:d26101f286c4 22 pc.printf("DataReceived %s \n", buffer);
kanatronics 0:d26101f286c4 23 pwmOut=atof(buffer);
kanatronics 0:d26101f286c4 24 pc.printf("%2.2f\n",pwmOut);
kanatronics 0:d26101f286c4 25 break;
kanatronics 0:d26101f286c4 26 }
kanatronics 0:d26101f286c4 27 }
kanatronics 0:d26101f286c4 28 }
kanatronics 0:d26101f286c4 29 }