I'm not sure what you are trying to do, your code is currently reflecting the input pin state, when it changes the output changes too.
Do you want to have a toggle effect so that once it is enabled it doesn't turn off, you can use a flag variable for that.
If you just want for the output to stay activated for a while you can use a delay.
Alex
---------- Post added at 15:56 ---------- Previous post was at 15:38 ----------
I woudn't use a delay this way because this would freeze the execution and the second condition would not be evaluated during that.
I would use a variable counter as delay
Code C - [expand] |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
| void main()
{
unsigned int d1=0,d2=0;
while(1)
{
if (d1==0) { // only evaluate the following condition when 0
if (input(pin_a0)==1)
{
output_low(pin_b0);
printf("Not available");
}
else
{
output_high(pin_b0);
printf("Available");
d1=10000; // set the value to start delay
}
}
else d1--;
if (d2==0) {
if(input(pin_a1)==1)
{
output_low(pin_b1);
printf("Not available");
}
else
{
output_high(pin_b1);
printf("Available");
d2=10000;
}
}
else d2--;
}
} |
Alex