![](/media/cache/group/mbed-logo-square-512_3.png.50x50_q85.png)
Additional CAN example
Diff: main.cpp
- Revision:
- 0:06f428d689e4
- Child:
- 1:5791101761f9
diff -r 000000000000 -r 06f428d689e4 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Jan 19 14:21:14 2017 -0600 @@ -0,0 +1,32 @@ +#include "mbed.h" + +Ticker ticker; +DigitalOut led1(LED1); +DigitalOut led2(LED2); +CAN can1(p9, p10); +CAN can2(p30, p29); +char counter = 0; + +void send() { + printf("send()\n"); + if(can1.write(CANMessage(1337, &counter;, 1))) { + printf("wloop()\n"); + counter++; + printf("Message sent: %d\n", counter); + } + led1 = !led1; +} + +int main() { + printf("main()\n"); + ticker.attach(&send;, 1); + CANMessage msg; + while(1) { + printf("loop()\n"); + if(can2.read(msg)) { + printf("Message received: %d\n", msg.data[0]); + led2 = !led2; + } + wait(0.2); + } +}