Created
February 17, 2024 21:25
-
-
Save maxpromer/0bff40601e999a6f4db6840063c809d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include <mcp2515.h> | |
MCP2515 mcp2515(10); | |
void setup() { | |
Serial.begin(115200); | |
mcp2515.reset(); | |
mcp2515.setBitrate(CAN_125KBPS, MCP_8MHZ); | |
mcp2515.setNormalMode(); | |
} | |
void loop() { | |
uint16_t adc = analogRead(A0); | |
struct can_frame frame; | |
frame.can_id = 0x7FF; | |
frame.can_dlc = 2; | |
frame.data[0] = adc >> 8; | |
frame.data[1] = adc & 0xFF; | |
if (mcp2515.sendMessage(&frame) == mcp2515.ERROR_OK) { | |
Serial.println("Send analog value OK"); | |
} else { | |
Serial.println("Send FAIL"); | |
} | |
delay(50); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment