I am making a program with a state machine. im using pir sensor and led. here is one of the lines of code:
if (currentState == 2 || currentState == 3) processPirState(currentState);
it should call this function when current state is either 2 or 3:
void processPirState(int currentState)
{
if(currentState == 2)
{
pirStat == digitalRead(pirPin);
if (pirStat == HIGH)
{
digitalWrite(ledPin, 1);
}
if (pirStat == LOW)
{
digitalWrite(ledPin, 0);
}
}
else if(currentState == 3)
{
digitalWrite(ledPin, 0);
}
}
however running the program and giving it 2 and 3 doesnt do anything in regards to the pir sensor. i feel like this is because it only gets called once as opposed to a loop, so it does indeed run but doesnt keep running therefore doesnt activate the pirsensor for more than 1 ms? please help, how would i go about solving this?