Loading...
Searching...
No Matches
MulticoreBasics.ino

Runs two sketches at once, one on each core of the RP2040. setup() and loop() run on core 0 as usual; defining setup1() and loop1() starts core 1, which runs them at the same time. Core 0 prints a count every second while core 1 blinks the LED: neither one's delay() holds up the other.

Works with Tools > Operating System set to None or FreeRTOS (SMP). See Multicore.

Output
Only core 0 prints. In the Serial Monitor at 115200 baud, setup() prints one line, then loop() prints a line every second, counting up from 0:
setup() runs on core 0
loop() on core 0: 0
loop() on core 0: 1
loop() on core 0: 2
Core 1's output is the LED: 100 ms on, 400 ms off, the whole time core 0 is printing.
// Runs two sketches at once, one on each core of the RP2040. setup() and
// loop() run on core 0 as usual; defining setup1() and loop1() starts core 1,
// which runs them at the same time. Core 0 prints a count every second while
// core 1 blinks the LED: neither one's delay() holds up the other.
void setup() {
Serial.begin(115200);
while (!Serial) {}
Serial.print("setup() runs on core ");
Serial.println(rp2040.cpuid());
}
void loop() {
static unsigned long count = 0;
Serial.print("loop() on core ");
Serial.print(rp2040.cpuid());
Serial.print(": ");
Serial.println(count++);
delay(1000);
}
void setup1() {
}
void loop1() {
delay(100);
delay(400);
}
@ OUTPUT
Definition Common.h:40
@ HIGH
Definition Common.h:32
@ LOW
Definition Common.h:31
SerialUSBClass Serial
USB serial port, the one the Serial Monitor uses.
void digitalWrite(pin_size_t pinNumber, PinStatus status)
Sets an output pin HIGH (3.3 V) or LOW (0 V).
void pinMode(pin_size_t pinNumber, PinMode pinMode)
Sets a pin as an input or an output.
void setup1(void) __attribute__((weak))
Written by the sketch (optional): runs once on core 1, at the same time as setup() on core 0.
RP2040Class rp2040
void loop1(void) __attribute__((weak))
Written by the sketch (optional): runs over and over on core 1 after setup1().
void loop(void)
Written by the sketch: runs over and over after setup(), on core 0.
void setup(void)
Written by the sketch: runs once after reset, on core 0.
void delay(unsigned long)
Waits a number of milliseconds.
#define LED_BUILTIN
On-board LED.
Definition pins_arduino.h:63