forked from arduino/ArduinoCore-mbed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasic_AddSub.ino
49 lines (40 loc) · 988 Bytes
/
Basic_AddSub.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "RPC.h"
int add(int a, int b) {
return a + b;
}
int sub(int a, int b) {
return a - b;
}
void setup() {
Serial.begin(115200);
while (!Serial) {
}
RPC.begin();
RPC.bind("add", add);
RPC.bind("sub", sub);
if (HAL_GetCurrentCPUID() == CM7_CPUID) {
// Introduce a brief delay to allow the M4 sufficient time
// to bind remote functions before invoking them.
delay(100);
}
pinMode(LEDG, OUTPUT);
}
void loop() {
static size_t loop_count = 0;
// Blink every 512 iterations
if (HAL_GetCurrentCPUID() == CM4_CPUID && (loop_count++ % 512) == 0) {
digitalWrite(LEDG, LOW);
delay(10);
digitalWrite(LEDG, HIGH);
delay(10);
}
int res = RPC.call("add", 1, 2).as<int>();
if (HAL_GetCurrentCPUID() == CM7_CPUID) {
Serial.println("add(1, 2) = " + String(res));
}
res = RPC.call("sub", res, 1).as<int>();
if (HAL_GetCurrentCPUID() == CM7_CPUID) {
Serial.println("sub(3, 1) = " + String(res));
}
delay(250);
}