source: rtos_arduino/trunk/arduino_lib/libraries/NcesCan/examples/send_Blink/send_Blink.ino@ 136

Last change on this file since 136 was 136, checked in by ertl-honda, 8 years ago

ライブラリとOS及びベーシックなサンプルの追加.

File size: 1.2 KB
Line 
1// demo: CAN-BUS Shield, send data
2#include <mcp_can.h>
3#include <SPI.h>
4
5// the cs pin of the version after v1.1 is default to D9
6// v0.9b and v1.0 is default D10
7const int SPI_CS_PIN = 9;
8const int ledHIGH = 1;
9const int ledLOW = 0;
10
11MCP_CAN CAN(SPI_CS_PIN); // Set CS pin
12
13void setup()
14{
15 Serial.begin(115200);
16
17START_INIT:
18
19 if(CAN_OK == CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
20 {
21 Serial.println("CAN BUS Shield init ok!");
22 }
23 else
24 {
25 Serial.println("CAN BUS Shield init fail");
26 Serial.println("Init CAN BUS Shield again");
27 delay(100);
28 goto START_INIT;
29 }
30}
31
32unsigned char stmp[8] = {ledHIGH, 1, 2, 3, ledLOW, 5, 6, 7};
33
34void loop()
35{ Serial.println("In loop");
36 // send data: id = 0x00, standrad frame, data len = 8, stmp: data buf
37 CAN.sendMsgBuf(0x70,0, 8, stmp);
38 delay(1000); // send data per 100ms
39}
40
41/*********************************************************************************************************
42 END FILE
43*********************************************************************************************************/
Note: See TracBrowser for help on using the repository browser.