/*********
Rui Santos
Complete project details at https://randomnerdtutorials.com
*********/
TaskHandle_t Task1;
TaskHandle_t Task2;
// LED pins
const int led1 = 12;
const int led2 = 12;
#define NOTE_E5 659
#define NOTE_D5 587
#define NOTE_G5 784
#define NOTE_A5 880
#define NOTE_C5 523
#define REST 0
void setup() {
Serial.begin(115200);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
//create a task that will be executed in the Task1code() function, with priority 1 and executed on core 0
xTaskCreatePinnedToCore(
Task1code, /* Task function. */
"Task1", /* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
1, /* priority of the task */
&Task1, /* Task handle to keep track of created task */
0); /* pin task to core 0 */
delay(500);
}
void Task1code( void * pvParameters ){
Serial.print("Task1 running on core ");
Serial.println(xPortGetCoreID());
while(1){
timeToMediAlarm();
}
}
void loop() {
}
void timeToMediAlarm() {
// Define the notes and durations
int melody[] = {
NOTE_E5, NOTE_E5, NOTE_D5, NOTE_E5, NOTE_G5, NOTE_G5, NOTE_A5, NOTE_G5,
NOTE_E5, NOTE_D5, NOTE_E5, NOTE_D5, NOTE_C5
};
int duration[] = {
8, 8, 8, 8, 8, 8, 4, 8,
8, 8, 8, 8, 4
};
for (int i = 0; i < sizeof(melody) / sizeof(melody[0]); i++) {
tone(26, melody[i], 1000 / duration[i]);
delay(1000 / duration[i] + 30); // Add a delay to distinguish between tones
noTone(26);
}
delay(2000); // Pause before repeating the melody
}