In the following bit of code, the DigitalIn within the while loop works fine and that data is assigned to the variables chanA and chanB. The IDENTICAL bit of code place before the loop will not function appropriately. I just dont get it. Is there something about placing these digital reads within a loop that makes them work. I must be doing something wrong. Can anyone set me straight here ??
<code>
int chanA, chanB, currState, prevState, change;
DigitalIn channelA(p24);
DigitalIn channelB(p25);
int main() {
pc.baud(38400);
channelA.mode(PullUp);
channelB.mode(PullUp);
chanA = channelA;
chanB = channelB;
printf(" %d %d \n",chanA, chanB);
while (1) {
chanA = channelA;
chanB = channelB;
printf("%d %d \n",chanA, chanB);
}
}
</code>
In the following bit of code, the DigitalIn within the while loop works fine and that data is assigned to the variables chanA and chanB. The IDENTICAL bit of code place before the loop will not function appropriately. I just dont get it. Is there something about placing these digital reads within a loop that makes them work. I must be doing something wrong. Can anyone set me straight here ??
<code> int chanA, chanB, currState, prevState, change;
DigitalIn channelA(p24); DigitalIn channelB(p25);
int main() {
pc.baud(38400);
channelA.mode(PullUp); channelB.mode(PullUp);
chanA = channelA; chanB = channelB;
printf(" %d %d \n",chanA, chanB);
while (1) {
chanA = channelA; chanB = channelB;
printf("%d %d \n",chanA, chanB); } }
</code>