Advertisement
Guest User

dismiss leaf startup dialogue

a guest
Nov 16th, 2020
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. //see https://www.mynissanleaf.com/viewtopic.php?p=593735#p593735 for details
  2. #include <avr/sleep.h>
  3. #include <mcp2515.h>  //https://github.com/autowp/arduino-mcp2515
  4. uint8_t sleepPin = 9; //for CAN transciever
  5. uint8_t csPin = 10;   //for CAN controller
  6. struct can_frame canMsg1 = { 0x681, 8, 0x04, 0x10, 0x40, 0x0D, 0xAB, 0xFF, 0xFF, 0xFF };
  7. struct can_frame canMsg2 = { 0x681, 8, 0x04, 0x20, 0x40, 0x0D, 0xAB, 0xFF, 0xFF, 0xFF };
  8. struct can_frame canMsg3 = { 0x681, 8, 0x04, 0x30, 0x40, 0x0D, 0xAB, 0xFF, 0xFF, 0xFF };
  9. MCP2515 mcp2515(csPin);
  10.  
  11. void setup() {
  12.   set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  13.   sleep_enable();  
  14.   pinMode(sleepPin, OUTPUT);
  15.   digitalWrite(sleepPin, LOW);
  16.   Serial.begin(115200);
  17.   while (!Serial); //only for boards with native usb
  18.   SPI.begin();
  19.   mcp2515.reset();
  20.   mcp2515.setBitrate(CAN_500KBPS, MCP_8MHZ); //check your quartz on mcp2515
  21.   mcp2515.setNormalMode();
  22.   Serial.println("Killing blue screen...");
  23. }
  24.  
  25. void loop() {
  26.   delay(8000); //delay for starting vehicle 8s
  27.   mcp2515.sendMessage(&canMsg1);
  28.   Serial.println("Message 1 sent");
  29.   delay(100);
  30.   mcp2515.sendMessage(&canMsg2);
  31.   Serial.println("Message 2 sent");
  32.   delay(100);
  33.   mcp2515.sendMessage(&canMsg3);
  34.   Serial.println("Message 3 sent");
  35.   delay(100);
  36.   Serial.println("Blue screen was killed!");
  37.   while (true){
  38.     digitalWrite(sleepPin, HIGH); //shutdown transciever
  39.     mcp2515.setSleepMode();       //shutdown controller
  40.     sleep_mode();                 //shutdown cpu
  41.     //shouldn't wake up, but just in case.
  42.   }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement