I have three functions (task4, task5 and task7). How can I use a queue to post and read the values from tasks 5 and 7?
I am using ESP32 and the Arduino IDE. This is my code:
byte POT_GPIO = 33; //analogue input
unsigned short int analg_val;//store analogue value
unsigned short int new_analg_val ;
unsigned short int filter_analg_val;//averaged analogue value
bool error_code;//high when average analogue input is greater than half its maximum range
//Task4 - Read analogue input using pot
void Task4() {
analg_val = analogRead(POT_GPIO);
}
//Task5 - Compute filtered analogue value
void Task5() {
new_analg_val = 0;
for (int i = 0; i <= 3; i++) { //take 4 readings
Task4();
new_analg_val = new_analg_val + analg_val;
}
filter_analg_val = new_analg_val / 4; //average of the last 4 readings
Serial.println(filter_analg_val);
}
//Task7 - Perform error check
void Task7() {
if (filter_analg_val > (0.5 * 4095)) { //4095 represents the max voltage
error_code = 1;
}
else {
error_code = 0;
}
Serial.println(error_code);
}
void setup() {
Serial.begin(9600);
pinMode(POT_GPIO, INPUT);
}
void loop() {
Task5();
Task7();
}