// Codice d'esempio basico per il calcolo parallelo
#define LED0 34
#define LED1 35
int i=0;
int j=0;
void setup() {
Serial.begin (115200);
pinMode(LED0, OUTPUT);
pinMode(LED1, OUTPUT);
xTaskCreatePinnedToCore (
myTask, // Function to implement the task
"myTask", // Name of the task
1000, // Stack size in bytes
NULL, // Task input parameter
0, // Priority of the task
NULL, // Task handle.
0 // Core where the task should run
);
}
// loop(): se non assegnato è sempre il core1 che gestisce questo
void loop() {
Serial.printf("Led %d, ciclo %d, eseguito dal core %d\n", LED0, i++, xPortGetCoreID());
digitalWrite (LED0, HIGH); // LED0 HIGH
delay (800);
digitalWrite (LED0, LOW); // LED0 LOW
delay (800);
}
// funzione myTask per il controllo parallelo
void myTask (void* pvParameters) {
while (1) {
Serial.printf("Led %d, ciclo %d, eseguito dal core %d\n", LED1, j++, xPortGetCoreID());
Serial.print ("Hello");
digitalWrite (LED1, HIGH); // LED1 HIGH
delay (300);
Serial.println (" World");
digitalWrite (LED1, LOW); // LED1 LOW
delay (300);
}
}