Guest User

arduino canhacker

a guest
Sep 30th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <can.h>
  2. #include <mcp2515.h>
  3.  
  4. #include <CanHacker.h>
  5. #include <CanHackerLineReader.h>
  6. #include <lib.h>
  7.  
  8. #include <SPI.h>
  9.  
  10. const int SPI_CS_PIN = 10;
  11. const int INT_PIN = 2;
  12.  
  13. CanHackerLineReader *lineReader = NULL;
  14. CanHacker *canHacker = NULL;
  15.  
  16. void setup() {
  17. Serial.begin(115200);
  18. SPI.begin();
  19.  
  20. canHacker = new CanHacker(&Serial, NULL, SPI_CS_PIN);
  21. lineReader = new CanHackerLineReader(canHacker);
  22.  
  23. canHacker->setClock(MCP_8MHZ);
  24.  
  25. pinMode(INT_PIN, INPUT);
  26. }
  27.  
  28. void loop() {
  29. if (digitalRead(INT_PIN) == LOW) {
  30. canHacker->processInterrupt();
  31. }
  32.  
  33. // uncomment that lines for Leonardo, Pro Micro or Esplora
  34. // if (Serial.available()) {
  35. // lineReader->process();
  36. // }
  37. }
  38.  
  39. // serialEvent handler not supported by Leonardo, Pro Micro and Esplora
  40. void serialEvent() {
  41. lineReader->process();
  42. }
Add Comment
Please, Sign In to add comment