Advertisement
XirallicBolts

Simple Rearview Camera Signal

Oct 2nd, 2019
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1.  
  2. // XirallicBolts
  3. // Basic example of sending Reverse signal when car is stopped in Sport gear.
  4.  
  5. #include <Canbus.h>
  6. #include <defaults.h>
  7. #include <global.h>
  8. #include <mcp2515.h>
  9. #include <mcp2515_defs.h>
  10.  
  11. void setup(){
  12.   Serial.begin(500000);
  13.   //Initialise MCP2515 CAN controller at the specified speed.  CANSPEED_500 for HS-CAN or I-CAN,  CANSPEED_125 for MS-CAN
  14.   if(Canbus.init(CANSPEED_500))
  15.     Serial.println("CAN Init ok");
  16.   else
  17.    Serial.println("Can't Init CAN");
  18.   delay(1000);
  19. }
  20.  
  21.  
  22. void loop(){
  23. tCAN message;
  24.  
  25. if (mcp2515_check_message())
  26. {
  27.     if (mcp2515_get_message(&message))
  28.     {
  29.         if(message.id == 0x109 and message.data[2] == 0x41  and message.data[4] < 0x02)
  30.         {
  31.             Serial.println("Car is stopped in S,  sending reverse signal");
  32.             message.data[2] = 0x11;    // Change the gear byte to 11 (Reverse)
  33.             mcp2515_bit_modify(CANCTRL, (1<<REQOP2)|(1<<REQOP1)|(1<<REQOP0), 0);
  34.             mcp2515_send_message(&message);
  35.         }
  36.      }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement