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
Diff: pwm.cpp
- Revision:
- 1:0bb74fa30daa
- Parent:
- 0:2263e23eb7e8
- Child:
- 2:4e86f37f1c1c
--- a/pwm.cpp Tue Oct 13 17:59:02 2015 +0000 +++ b/pwm.cpp Tue Oct 20 17:10:53 2015 +0000 @@ -3,23 +3,32 @@ Ticker ticker; DigitalOut led1(LED1); DigitalOut led2(LED2); +PwmOut pwmx(p26); +PwmOut pwmy(p25); CAN can2(p30, p29); char counter = 0; int x=0; int y=0; + +#define PERIOD 0.000005 +#define MAX 1300.0f void send() { } int main() { - printf("main()\n"); + printf("main d()\n"); ticker.attach(&send, 1); CANMessage msg; can2.frequency(1000000); + pwmx.period(PERIOD); // 4 second period + pwmy.period(PERIOD); while(1) { // printf("loop()\n"); if(can2.read(msg)) { - x = msg.data[4]; - y = msg.data[0]; + x = ((int) msg.data[5])*255 + ((int)msg.data[4]); + y = ((int)msg.data[1])*255 + ((int) msg.data[0]); + pwmx.write(x/MAX); + pwmy.write(1-y/MAX); printf("Message received: x %d %d %d %d %d %d %d %d %d %d\r\n",msg.data[0],msg.data[1],msg.data[2],msg.data[3],msg.data[4],msg.data[5],msg.data[6],msg.data[7], x , y); led2 = !led2; }