samedi 3 octobre 2015

Arduino While loop and if statement logic

Looking for some help with some loop logic. Right now, this just gets stuck in a while loop but doesn't break. Mostly just curious, but how could I do this so the Serial write continues to just write every time, but the lightThis() function is only called once?

void loop(){
    if ( (x >= 245 && x <= 260) && (accelDifference > STAB_THRESHOLD)){
    // write a command to serial
    Serial.print("p1stab");

    // trace this for now
    Serial.print("\t");
    Serial.print(x);
    Serial.print("\t");
    Serial.print(y);
    Serial.print("\t");
    Serial.print(z);
    Serial.print("\n");

    // keep the LED solid 
    while(true) {
        lightThis();
        if (false){
            break;
        }
    }

    } else {
        Bean.setLed(0, 0, 0);
    }

}

Thanks!

Aucun commentaire:

Enregistrer un commentaire