//Salma Azra Fatimah - 2006465880
//Assignment B NO 1
void sum_number(void * parameters) {
int n1 = 1;
int sum = 1;
char print_buf[300];
for (;;) {
sprintf(print_buf, "Sum Number Term %d: %d\n", n1, sum);
Serial.println(print_buf);
n1 = n1 + 1;
sum = sum+n1;
if (n1 >= 100) break;
vTaskDelay(50 / portTICK_PERIOD_MS);
}
}
void blink_led (void * parameters) {
int pin_LED = 26;
pinMode(pin_LED,OUTPUT);
int n1 = 1;
bool ON = false;
char print_buf[300];
for (;;) {
sprintf(print_buf, "LED Term %d = %s \n", n1, ((ON)?"ON":"OFF"));
Serial.println(print_buf);
digitalWrite(pin_LED, ((ON)?HIGH:LOW));
ON = (ON) ? false:true;
n1 = n1 + 1;
//sum = sum+n1;
if (n1 >= 100) break;
vTaskDelay(50 / portTICK_PERIOD_MS);
}
}
void print_fibonacci (void * parameters) {
int n1 = 0;
int n2 = 1;
int term = 0;
char print_buf[300];
sprintf(print_buf, "Fibonacci Term %d: %d\n", term, n1);
Serial.print(print_buf);
term = term + 1;
sprintf(print_buf, "Fibonacci Term %d: %d\n", term, n1);
Serial.print(print_buf);
for (;;) {
term = term + 1;
int n3 = n1 + n2;
sprintf(print_buf, "Fibonacci Term %d: %d\n", term, n3);
Serial.println(print_buf);
n1 = n2;
n2 = n3;
if (term >= 25) break;
vTaskDelay(100 / portTICK_PERIOD_MS);
}
}
void setup() {
Serial.begin(115200);
xTaskCreate(
sum_number, // Function that should be called
"Sum Numbers", // Name of the task (for debugging)
10000, // Stack size (bytes)
NULL, // Parameter to pass
1, // Task priority
NULL // Task handle
);
xTaskCreate(
blink_led, // Function that should be called
"Blink LED", // Name of the task (for debugging)
10000, // Stack size (bytes)
NULL, // Parameter to pass
1, // Task priority
NULL // Task handle
);
xTaskCreate(
print_fibonacci, // Function that should be called
"Print Fibonacci", // Name of the task (for debugging)
10000, // Stack size (bytes)
NULL, // Parameter to pass
1, // Task priority
NULL // Task handle
);
}
void loop(){
}