Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //see https://www.mynissanleaf.com/viewtopic.php?p=593735#p593735 for details
- #include <avr/sleep.h>
- #include <mcp2515.h> //https://github.com/autowp/arduino-mcp2515
- uint8_t sleepPin = 9; //for CAN transciever
- uint8_t csPin = 10; //for CAN controller
- struct can_frame canMsg1 = { 0x681, 8, 0x04, 0x10, 0x40, 0x0D, 0xAB, 0xFF, 0xFF, 0xFF };
- struct can_frame canMsg2 = { 0x681, 8, 0x04, 0x20, 0x40, 0x0D, 0xAB, 0xFF, 0xFF, 0xFF };
- struct can_frame canMsg3 = { 0x681, 8, 0x04, 0x30, 0x40, 0x0D, 0xAB, 0xFF, 0xFF, 0xFF };
- MCP2515 mcp2515(csPin);
- void setup() {
- set_sleep_mode(SLEEP_MODE_PWR_DOWN);
- sleep_enable();
- pinMode(sleepPin, OUTPUT);
- digitalWrite(sleepPin, LOW);
- Serial.begin(115200);
- while (!Serial); //only for boards with native usb
- SPI.begin();
- mcp2515.reset();
- mcp2515.setBitrate(CAN_500KBPS, MCP_8MHZ); //check your quartz on mcp2515
- mcp2515.setNormalMode();
- Serial.println("Killing blue screen...");
- }
- void loop() {
- delay(8000); //delay for starting vehicle 8s
- mcp2515.sendMessage(&canMsg1);
- Serial.println("Message 1 sent");
- delay(100);
- mcp2515.sendMessage(&canMsg2);
- Serial.println("Message 2 sent");
- delay(100);
- mcp2515.sendMessage(&canMsg3);
- Serial.println("Message 3 sent");
- delay(100);
- Serial.println("Blue screen was killed!");
- while (true){
- digitalWrite(sleepPin, HIGH); //shutdown transciever
- mcp2515.setSleepMode(); //shutdown controller
- sleep_mode(); //shutdown cpu
- //shouldn't wake up, but just in case.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement