-
Notifications
You must be signed in to change notification settings - Fork 0
Async
davidmoshal edited this page Mar 18, 2023
·
2 revisions
#include "main.h"
int counter_one = 0;
int counter_two = 0;
void print_msg_1(void* params){
int delay = *(int*)params;
std::cout << "print_msg_1 " << delay << std::endl;
while(true){
counter_one++;
pros::lcd::print(5, "counter one: %d", counter_one);
pros::delay(delay);
}
}
void print_msg_2(void* params){
int delay = *(int*)params;
std::cout << "print_msg_2: " << delay << std::endl;
while(true){
counter_two++;
pros::lcd::print(6, "counter two: %d", counter_two);
pros::delay(delay);
}
}
int delay_one = 500;
int delay_two = 1000;
void initialize() {
pros::lcd::initialize();
pros::lcd::set_text(1, "Hello David User!");
pros::Task my_task1(print_msg_1, &delay_one, "My Task Name");
pros::Task my_task2(print_msg_2, &delay_two, "My Task Name");
}
void disabled() {}
void competition_initialize() {}
void autonomous() {}
void opcontrol() {
while (true) {
pros::delay(20);
}
}Note:
- integer was passed by address and derefenced by
*(int*)params. - the integer i must be global scope, otherwise it is a random address (??)
void my_fn_1(void* params){
int delay = *(int*)params;
}
int i = 0;
void initialize() {
pros::Task my_task1(my_fn_1, &i, "My Task Name");
}