高石 龍河
/
mbed_blinky
m
main.cpp@0:0cd6efbaafa4, 2019-03-13 (annotated)
- Committer:
- Ryuga
- Date:
- Wed Mar 13 03:38:18 2019 +0000
- Revision:
- 0:0cd6efbaafa4
m;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Ryuga | 0:0cd6efbaafa4 | 1 | #include "mbed.h" |
Ryuga | 0:0cd6efbaafa4 | 2 | |
Ryuga | 0:0cd6efbaafa4 | 3 | Ticker ticker; |
Ryuga | 0:0cd6efbaafa4 | 4 | DigitalOut led1(LED1); |
Ryuga | 0:0cd6efbaafa4 | 5 | DigitalOut led2(LED2); |
Ryuga | 0:0cd6efbaafa4 | 6 | CAN can1(p9, p10); |
Ryuga | 0:0cd6efbaafa4 | 7 | CAN can2(p30, p29); |
Ryuga | 0:0cd6efbaafa4 | 8 | char counter = 0; |
Ryuga | 0:0cd6efbaafa4 | 9 | |
Ryuga | 0:0cd6efbaafa4 | 10 | void send() { |
Ryuga | 0:0cd6efbaafa4 | 11 | printf("send()\n"); |
Ryuga | 0:0cd6efbaafa4 | 12 | if(can1.write(CANMessage(1337, &counter, 1))) { |
Ryuga | 0:0cd6efbaafa4 | 13 | printf("wloop()\n"); |
Ryuga | 0:0cd6efbaafa4 | 14 | counter++; |
Ryuga | 0:0cd6efbaafa4 | 15 | printf("Message sent: %d\n", counter); |
Ryuga | 0:0cd6efbaafa4 | 16 | } |
Ryuga | 0:0cd6efbaafa4 | 17 | led1 = !led1; |
Ryuga | 0:0cd6efbaafa4 | 18 | } |
Ryuga | 0:0cd6efbaafa4 | 19 | |
Ryuga | 0:0cd6efbaafa4 | 20 | int main() { |
Ryuga | 0:0cd6efbaafa4 | 21 | printf("main()\n"); |
Ryuga | 0:0cd6efbaafa4 | 22 | ticker.attach(&send, 1); |
Ryuga | 0:0cd6efbaafa4 | 23 | CANMessage msg; |
Ryuga | 0:0cd6efbaafa4 | 24 | while(1) { |
Ryuga | 0:0cd6efbaafa4 | 25 | printf("loop()\n"); |
Ryuga | 0:0cd6efbaafa4 | 26 | if(can1.read(msg)) { |
Ryuga | 0:0cd6efbaafa4 | 27 | printf("Message received: %d\n", msg.data[0]); |
Ryuga | 0:0cd6efbaafa4 | 28 | led2 = !led2; |
Ryuga | 0:0cd6efbaafa4 | 29 | } |
Ryuga | 0:0cd6efbaafa4 | 30 | wait(0.2); |
Ryuga | 0:0cd6efbaafa4 | 31 | } |
Ryuga | 0:0cd6efbaafa4 | 32 | } |