Pages: 1 [2]   Go Down
Author Topic: How to Create logic  (Read 952 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12549
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your diagram shows that you have got pull-down resistors in place so you do not have floating inputs. (I assume these resistors are in place for all four inputs used by your sketch.)

I think the problem is that these conditions are not all mutually exclusive:

Code:
if (P1State == HIGH)
if (L2State == HIGH)
if (L1State ==HIGH)
if (L2State ==HIGH && P1State==HIGH)

This means that even if you correctly turn the outputs off in one piece of code, they could be turned on again by another piece of code.

I suggest you restructure so that they are mutually exclusive and the precedence between them is defined explicitly, e.g.:

Code:
if (L2State == HIGH && P1State == HIGH)
{
}
else
{
    if (P1State == HIGH)
    {
    }
    if (L2State == HIGH)
    {
    }
}
if (L1State == HIGH)
{
}
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Pages: 1 [2]   Go Up
Jump to: