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
pwm.cpp@1:0bb74fa30daa, 2015-10-20 (annotated)
- Committer:
- Blasko
- Date:
- Tue Oct 20 17:10:53 2015 +0000
- Revision:
- 1:0bb74fa30daa
- Parent:
- 0:2263e23eb7e8
- Child:
- 2:4e86f37f1c1c
p4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Blasko | 0:2263e23eb7e8 | 1 | #include "mbed.h" |
Blasko | 0:2263e23eb7e8 | 2 | |
Blasko | 0:2263e23eb7e8 | 3 | Ticker ticker; |
Blasko | 0:2263e23eb7e8 | 4 | DigitalOut led1(LED1); |
Blasko | 0:2263e23eb7e8 | 5 | DigitalOut led2(LED2); |
Blasko | 1:0bb74fa30daa | 6 | PwmOut pwmx(p26); |
Blasko | 1:0bb74fa30daa | 7 | PwmOut pwmy(p25); |
Blasko | 0:2263e23eb7e8 | 8 | CAN can2(p30, p29); |
Blasko | 0:2263e23eb7e8 | 9 | char counter = 0; |
Blasko | 0:2263e23eb7e8 | 10 | int x=0; |
Blasko | 0:2263e23eb7e8 | 11 | int y=0; |
Blasko | 1:0bb74fa30daa | 12 | |
Blasko | 1:0bb74fa30daa | 13 | #define PERIOD 0.000005 |
Blasko | 1:0bb74fa30daa | 14 | #define MAX 1300.0f |
Blasko | 0:2263e23eb7e8 | 15 | void send() { |
Blasko | 0:2263e23eb7e8 | 16 | |
Blasko | 0:2263e23eb7e8 | 17 | } |
Blasko | 0:2263e23eb7e8 | 18 | int main() { |
Blasko | 1:0bb74fa30daa | 19 | printf("main d()\n"); |
Blasko | 0:2263e23eb7e8 | 20 | ticker.attach(&send, 1); |
Blasko | 0:2263e23eb7e8 | 21 | CANMessage msg; |
Blasko | 0:2263e23eb7e8 | 22 | can2.frequency(1000000); |
Blasko | 1:0bb74fa30daa | 23 | pwmx.period(PERIOD); // 4 second period |
Blasko | 1:0bb74fa30daa | 24 | pwmy.period(PERIOD); |
Blasko | 0:2263e23eb7e8 | 25 | while(1) { |
Blasko | 0:2263e23eb7e8 | 26 | // printf("loop()\n"); |
Blasko | 0:2263e23eb7e8 | 27 | if(can2.read(msg)) { |
Blasko | 1:0bb74fa30daa | 28 | x = ((int) msg.data[5])*255 + ((int)msg.data[4]); |
Blasko | 1:0bb74fa30daa | 29 | y = ((int)msg.data[1])*255 + ((int) msg.data[0]); |
Blasko | 1:0bb74fa30daa | 30 | pwmx.write(x/MAX); |
Blasko | 1:0bb74fa30daa | 31 | pwmy.write(1-y/MAX); |
Blasko | 0:2263e23eb7e8 | 32 | 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); |
Blasko | 0:2263e23eb7e8 | 33 | led2 = !led2; |
Blasko | 0:2263e23eb7e8 | 34 | } |
Blasko | 0:2263e23eb7e8 | 35 | wait(0.05); |
Blasko | 0:2263e23eb7e8 | 36 | } |
Blasko | 0:2263e23eb7e8 | 37 | } |