Kamil Kanas
/
Nucleo_PWM_Serial_Motor_Controller
PWM motor controler. Serial DAQ float 0 upto 1
main.cpp@0:d26101f286c4, 2016-06-24 (annotated)
- Committer:
- kanatronics
- Date:
- Fri Jun 24 14:54:11 2016 +0000
- Revision:
- 0:d26101f286c4
- Child:
- 1:a3dae8744a7d
PWM serial speed controller. Float DAQ 0 up to 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kanatronics | 0:d26101f286c4 | 1 | /*Kamil Kanas |
kanatronics | 0:d26101f286c4 | 2 | Nucleo PWM to Serial motor controller |
kanatronics | 0:d26101f286c4 | 3 | Tested 24/6/2016 |
kanatronics | 0:d26101f286c4 | 4 | */ |
kanatronics | 0:d26101f286c4 | 5 | |
kanatronics | 0:d26101f286c4 | 6 | #include "mbed.h" |
kanatronics | 0:d26101f286c4 | 7 | #define led_green D13 |
kanatronics | 0:d26101f286c4 | 8 | //DigitalOut green(led_green); |
kanatronics | 0:d26101f286c4 | 9 | Serial pc(USBTX,USBRX); |
kanatronics | 0:d26101f286c4 | 10 | PwmOut led(D13); |
kanatronics | 0:d26101f286c4 | 11 | |
kanatronics | 0:d26101f286c4 | 12 | float pwmOut; |
kanatronics | 0:d26101f286c4 | 13 | char buffer[16]; |
kanatronics | 0:d26101f286c4 | 14 | |
kanatronics | 0:d26101f286c4 | 15 | int main() { |
kanatronics | 0:d26101f286c4 | 16 | pc.baud(115200); /*Set baud rate*/ |
kanatronics | 0:d26101f286c4 | 17 | |
kanatronics | 0:d26101f286c4 | 18 | while (1){ |
kanatronics | 0:d26101f286c4 | 19 | led=pwmOut; |
kanatronics | 0:d26101f286c4 | 20 | while(true){ |
kanatronics | 0:d26101f286c4 | 21 | if(pc.readable()) { /*if data in the ring buffer*/ |
kanatronics | 0:d26101f286c4 | 22 | pc.gets(buffer, 8); |
kanatronics | 0:d26101f286c4 | 23 | pc.printf("DataReceived %s \n", buffer); |
kanatronics | 0:d26101f286c4 | 24 | //dataInt = atoi(buffer); |
kanatronics | 0:d26101f286c4 | 25 | //pc.printf("%d \n",dataInt); |
kanatronics | 0:d26101f286c4 | 26 | pwmOut=atof(buffer); |
kanatronics | 0:d26101f286c4 | 27 | pc.printf("%2.2f\n",pwmOut); |
kanatronics | 0:d26101f286c4 | 28 | break; |
kanatronics | 0:d26101f286c4 | 29 | } |
kanatronics | 0:d26101f286c4 | 30 | } |
kanatronics | 0:d26101f286c4 | 31 | } |
kanatronics | 0:d26101f286c4 | 32 | } |