Updated for latest PlatformIO

This commit is contained in:
2023-10-27 23:49:02 +02:00
parent 627c0e3884
commit ee5c88e9b2
+20 -13
View File
@@ -1,18 +1,17 @@
/************************************* /*************************************
* CAN-bus receive * arduino-can-bus-receive
* Author: Michel Bats * Author: Michel Bats
* Website: www.batssoft.nl * Website: www.batssoft.nl
* Version: 0.0.2
* Revision: 20190418
*************************************/ *************************************/
#include <Arduino.h>
#include <SPI.h> #include <SPI.h>
#include <mcp_can.h> #include <mcp_can.h>
#include <Adafruit_GFX.h> #include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h> #include <Adafruit_SSD1306.h>
// Bepalingen Display // Bepalingen Display
#define OLED_ADDR 60 // 60 = 0x3C / 61 = 0x3D #define OLED_ADDR 60 // 60 = 0x3C / 61 = 0x3D
#define SCREEN_WIDTH 128 // OLED-scherm breedte, in pixels #define SCREEN_WIDTH 128 // OLED-scherm breedte, in pixels
#define SCREEN_HEIGHT 64 // OLED-scherm hoogte, in pixels #define SCREEN_HEIGHT 64 // OLED-scherm hoogte, in pixels
#define OLED_RESET 4 #define OLED_RESET 4
@@ -40,6 +39,8 @@ Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Initialisatie mcp_can // Initialisatie mcp_can
MCP_CAN CAN(MCP_CAN_SPI_CS_PIN); MCP_CAN CAN(MCP_CAN_SPI_CS_PIN);
void canIdToReadChange();
// SETUP // SETUP
void setup() void setup()
{ {
@@ -92,13 +93,12 @@ void loop()
unsigned char len = 0; unsigned char len = 0;
unsigned char buf[12]; unsigned char buf[12];
if (CAN_MSGAVAIL == CAN.checkReceive()) // check if data coming if (CAN_MSGAVAIL == CAN.checkReceive()) // check if data coming
{ {
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
unsigned int canId = CAN.getCanId(); unsigned int canId = CAN.getCanId();
if (canId == canIdToRead) if (canId == canIdToRead)
{ {
bufDisp[0] = buf[0]; bufDisp[0] = buf[0];
@@ -133,7 +133,9 @@ void loop()
if (i == 3) if (i == 3)
{ {
display.println(bufDisp[i], HEX); display.println(bufDisp[i], HEX);
} else { }
else
{
display.print(bufDisp[i], HEX); display.print(bufDisp[i], HEX);
display.print(" "); display.print(" ");
} }
@@ -147,10 +149,12 @@ void loop()
display.display(); display.display();
display.clearDisplay(); display.clearDisplay();
tel++; tel++;
if (tel > 999999) { if (tel > 999999)
{
tel = 0; tel = 0;
} }
} else if (tel == 0) }
else if (tel == 0)
{ {
display.setCursor(0, 0); display.setCursor(0, 0);
display.println(" SEL CUR DIS"); display.println(" SEL CUR DIS");
@@ -169,12 +173,15 @@ void loop()
} }
} }
void canIdToReadChange() { void canIdToReadChange()
while(digitalRead(INTERRUPT_PIN) == 0){ {
while (digitalRead(INTERRUPT_PIN) == 0)
{
delay(250); delay(250);
} }
canIdCount++; canIdCount++;
if (canIdCount > CAN_ID_COUNT) { if (canIdCount > CAN_ID_COUNT)
{
canIdCount = 0; canIdCount = 0;
} }
canIdToRead = canIdToReadArray[canIdCount]; canIdToRead = canIdToReadArray[canIdCount];