I can't get 'while' to work :'(

Bah... I can't get while to work... even simped down my code :(

Any ideas? and I know I'm prolly just missing some...thing. (Either way, thanks!)

(It never leaves the while loop, no matter what the button state)

void loop() { bumpSensorState= digitalRead (bumpSensor);

while (bumpSensorState=HIGH) { motor1.setSpeed(255); motor2.setSpeed(255); motor1.run(FORWARD); motor2.run(FORWARD); bumpSensorState= digitalRead (bumpSensor); }

motor1.setSpeed(255); motor2.setSpeed(200); motor1.run(BACKWARD); motor2.run(BACKWARD); //{run backwardSub} delay (4000); }

This: (bumpSensorState=HIGH) is an assignment not a comparison. Because you assign bumpSensorState to HIGH which is 1, then this will always be true as 1 (true) != 0 (false).

Try: (bumpSensorState == HIGH)

oh godda**it :)


Yeah... I had to train myself over and over...

See: --> "=" THINK: --> "IS SET TO"

See: --> "==" THINK: --> "IS EQUAL TO"

One thing I try to do when comparing to a constant is to put the constant (HIGH) on the LEFT side of the equals. This way, if I left off the extra equals sign, it's flagged as an error by the compiler instead of merrily generating the wrong code for what I want to do.

It's just an idea...


(Heck, as long as this post is near the top anyways : )

Again, thanks... I'ma do yoda speak for those from now on :)