const int oTransistor1 = 26;
const int iPulsador1 = 32;
int cnt = 0;
TaskHandle_t t1;
TaskHandle_t t2;
void setup() {
pinMode(iPulsador1, INPUT); // entrada de pulsador reset wifi
pinMode(oTransistor1, OUTPUT);
cnt = 0;
Serial.begin(115200);
xTaskCreate(
tarea1, /* Function to implement the task */
"tarea1", /* Name of the task */
10000, /* Stack size in words */
NULL, /* Task input parameter */
0, /* Priority of the task */
&t1);
xTaskCreate(
tarea2, /* Function to implement the task */
"tarea2", /* Name of the task */
10000, /* Stack size in words */
NULL, /* Task input parameter */
1, /* Priority of the task */
&t2);
}
int cnt1=0;
int filtro1=10;
int cnt1on=0;
int cnt1off=0;
int flag1=0;
void loop() {
delay(1);
cntMaq(&cnt1, iPulsador1, filtro1, &cnt1on, &cnt1off, &flag1);
// cntMaq (&cnt1, iPulsador1, &filtro1, &cnton1, &cntoff1, &mFlag1);
}
void cntMaq (int *cnt, int entrada, int filtro, int *cnton, int *cntoff, int *mFlag) {
// esperamos a que valga 1 o cero un numero de scans
if (!digitalRead(entrada)) {
*cnton = *cnton + 1;
*cntoff = 0;
if (*cnton > 10000)
*cnton = 10000;
} else {
*cntoff = *cntoff + 1;
*cnton = 0;
if (*cntoff > 10000)
*cntoff = 10000;
}
// se ha activado
if (*cnton > filtro && *mFlag == 0) {
// incrementamos el contador
*cnt = *cnt + 1;
*mFlag = 1;
}
// se ha desactivado
if (*cntoff > filtro) {
*mFlag = 0;
}
}
void tarea1(void *parameter) {
// Increment the counter and set the time of ISR
while (true) {
delay(1000);
Serial.println(cnt1);
//cnt++;
}
}
void tarea2(void *parameter) {
// Increment the counter and set the time of ISR
while (true) {
//Serial.println("hola");
delay(10);
cnt--;
}
}