Hi There,
I have two task. task2 works fine, but when task1 trigger then CPU got hang.
How to fix it?
CPU: Arduino UNO (ATmega328P)
Code is following:
#include <Arduino_FreeRTOS.h>
/*******************xTask for ****************************/
void scanButton(void *pvParameters)
{
int itr=0;
bool readBtnStatus;
pinMode(11, INPUT);
pinMode(0, OUTPUT);
while(1)
{
readBtnStatus = digitalRead(11);
vTaskDelay( 100);
if(readBtnStatus)
{
if(itr >= 2)
{
digitalWrite(0, HIGH);
itr = 0;
}
else
{
digitalWrite(0, LOW);
itr++;
}
}
//vTaskDelay(10);
}
}
/*******************xTask for ****************************/
void controlLoad(void *pvParameters)
{
bool lowswitch = 0;
bool highswitch = 0;
bool passswitch = 0;
pinMode(1,INPUT); //low switch
pinMode(2,INPUT); //pass switch
pinMode(4,INPUT); //high switch
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
while(1)
{
lowswitch = digitalRead(1);
passswitch = digitalRead(2);
highswitch = digitalRead(4);
if (lowswitch == 1 && highswitch == 0 && passswitch == 0)
{
digitalWrite(10,LOW);
digitalWrite(9,HIGH);
}
else if (lowswitch == 0 && highswitch == 1 && passswitch == 0)
{
digitalWrite(10,HIGH);
digitalWrite(9,LOW);
}
else if (lowswitch == 0 && highswitch == 0 && passswitch == 1)
{
digitalWrite(10,HIGH);
vTaskDelay( 150 );
digitalWrite(10,LOW);
vTaskDelay( 150 );
digitalWrite(9,LOW);
}
else if (lowswitch == 1 && highswitch == 0 && passswitch == 1)
{
digitalWrite(9,LOW);
digitalWrite(10,HIGH);
vTaskDelay( 150 );
digitalWrite(10,LOW);
digitalWrite(9,HIGH);
vTaskDelay( 150 );
}
else if (lowswitch == 0 && highswitch == 1 && passswitch == 1)
{
digitalWrite(10,LOW);
digitalWrite(9,HIGH);
vTaskDelay( 150 );
digitalWrite(9,LOW);
digitalWrite(10,HIGH);
vTaskDelay( 150 );
}
else if (lowswitch == 1 && highswitch == 1)
{
digitalWrite(10,HIGH);
digitalWrite(9,HIGH);
}
else
{
digitalWrite(10,LOW);
digitalWrite(9,LOW);
}
vTaskDelay(10);
}
}
/******************* Setup ****************************/
void setup()
{
Serial.begin(9600);
xTaskCreate(scanButton, "task1", 512, NULL, 2, NULL );
xTaskCreate(controlLoad, "task2", 512, NULL, 1, NULL );
}
void loop()
{
}