Go Down

Topic: WHILE problem.. need help! (Read 1 time) previous topic - next topic


May 14, 2010, 01:47 pm Last Edit: May 14, 2010, 01:50 pm by GrooveFlotilla Reason: 1
Code: [Select]
//the problem is [u]not[/u] here

[edit]Is there some significance about translating 0x69 to 1, and 0x72 to 0? You're using a "switch" - why not use the original values?[/edit]
Per Arduino ad Astra


I can use  and the original stuff like

Code: [Select]
if (i==1) { while (i!=0) {
digitalWrite(ledPin, digitalRead(pPin));}}
else if (i==0) digitalWrite(ledPin, LOW);

its not the point.  the problem i think is in while ...  the value of i is not changed in while.


when i do stuff like
Code: [Select]
if (i==1) digitalWrite(ledPin, HIGH);    
if (i==0) digitalWrite(ledPin, LOW);

it works !

but with while  no ...


May 14, 2010, 02:14 pm Last Edit: May 14, 2010, 02:16 pm by PaulS Reason: 1
The variable i is assigned a value based on the value returned by kbd.read(). If you never call that function again, and never re-assign i a new value, I'm at a loss to understand why you expect the value of i to change.

You are not binding i to the value output by kdb.read(), so that a change in which key is pressed automatically assigns a new value to i.

Perhaps you are misunderstanding the purpose of while, using it where you mean if. The while statement is used to do something over and over, until the termination condition is true. The if statement is used to do something once if the condition is true.


look people , i know my code is fine !  I need only  the corect sintax !

look people , I can do :
Code: [Select]
If (i==1) digitalWrite(ledPin, digitalRead(pPin));
if (i==0) digitalWrite(ledPin, LOW);

but I need while (i==1) to do  digitalWrite(ledPin, digitalRead(pPin));
and while (i==0) to do digitalWrite(ledPin, LOW);

the value of i is changed before this stuff !  what is the right sintax ?

Go Up