Lab_interaccio/2024/RPC_test/RPC_test.ino
2025-02-25 21:29:42 +01:00

48 lines
946 B
C++

#include "Arduino.h"
#include "RPC.h"
#include "SerialRPC.h"
using namespace rtos;
Thread subtractThread;
/**
Returns the CPU that's currently running the sketch (M7 or M4)
Note that the sketch has to be uploaded to both cores.
**/
String currentCPU() {
if (RPC.cpu_id() == CM7_CPUID) {
return "M7";
} else {
return "M4";
}
}
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
// Initialize RPC library; this also boots the M4 core
Serial.begin(115200);
if (!SerialRPC.begin()) {
Serial.println("RPC initialization fail");
}
}
void loop() {
if (currentCPU() == "M4") {
if (SerialRPC.available()) {
char read= (char)SerialRPC.read(); // Fill the buffer with characters
if (read=='1') digitalWrite(LED_BUILTIN, HIGH);
else digitalWrite(LED_BUILTIN, LOW);
}
}
if (currentCPU() == "M7") {
SerialRPC.print('1');
delay(1000);
SerialRPC.print('0');
delay(1000);
}
}