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.
main.cpp@0:68f5325bc455, 2017-08-17 (annotated)
- Committer:
- lcaepusp
- Date:
- Thu Aug 17 20:59:23 2017 +0000
- Revision:
- 0:68f5325bc455
- Child:
- 1:7c69af307591
teste1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lcaepusp | 0:68f5325bc455 | 1 | #include "mbed.h" |
lcaepusp | 0:68f5325bc455 | 2 | |
lcaepusp | 0:68f5325bc455 | 3 | Ticker ticker; |
lcaepusp | 0:68f5325bc455 | 4 | DigitalOut led1(LED1); |
lcaepusp | 0:68f5325bc455 | 5 | DigitalOut led2(LED2); |
lcaepusp | 0:68f5325bc455 | 6 | CAN can1(p9, p10); |
lcaepusp | 0:68f5325bc455 | 7 | CAN can2(p30, p29); |
lcaepusp | 0:68f5325bc455 | 8 | char counter = 0; |
lcaepusp | 0:68f5325bc455 | 9 | |
lcaepusp | 0:68f5325bc455 | 10 | void send() { |
lcaepusp | 0:68f5325bc455 | 11 | printf("send()\n"); |
lcaepusp | 0:68f5325bc455 | 12 | if(can1.write(CANMessage(1337, &counter, 1))) { |
lcaepusp | 0:68f5325bc455 | 13 | printf("wloop()\n"); |
lcaepusp | 0:68f5325bc455 | 14 | counter++; |
lcaepusp | 0:68f5325bc455 | 15 | printf("Message sent: %d\n", counter); |
lcaepusp | 0:68f5325bc455 | 16 | } |
lcaepusp | 0:68f5325bc455 | 17 | led1 = !led1; |
lcaepusp | 0:68f5325bc455 | 18 | } |
lcaepusp | 0:68f5325bc455 | 19 | |
lcaepusp | 0:68f5325bc455 | 20 | int main() { |
lcaepusp | 0:68f5325bc455 | 21 | printf("main()\n"); |
lcaepusp | 0:68f5325bc455 | 22 | ticker.attach(&send, 1); |
lcaepusp | 0:68f5325bc455 | 23 | CANMessage msg; |
lcaepusp | 0:68f5325bc455 | 24 | while(1) { |
lcaepusp | 0:68f5325bc455 | 25 | printf("loop()\n"); |
lcaepusp | 0:68f5325bc455 | 26 | if(can2.read(msg)) { |
lcaepusp | 0:68f5325bc455 | 27 | printf("Message received: %d\n", msg.data[0]); |
lcaepusp | 0:68f5325bc455 | 28 | led2 = !led2; |
lcaepusp | 0:68f5325bc455 | 29 | } |
lcaepusp | 0:68f5325bc455 | 30 | wait(0.2); |
lcaepusp | 0:68f5325bc455 | 31 | } |
lcaepusp | 0:68f5325bc455 | 32 | } |