lundi 27 mars 2017

How to convert a C ternary statement into an if/else if declared within an if condition?

So after looking on the massive interweb, I was unable to find an answer to this.

Say I have this piece of code:

if(P4IN & GPIO_PIN1?0:1){
        if (state==1){
            state = 0;
            //Wait for this state to pass -- ends up saving the current state on button press.
            while (counter < 10000){
                counter++;
            }
        }
        else{
            state = 1;
            while (counter < 10000){
                counter++;
            }
        }
    }

How would I rewrite this so that "if(P4IN & GPIO_PIN1?0:1)" is not written like this. I do not mind creating extra if/else conditions or extending this block of code (intended for the MSP432)

Thanks for your time.

Aucun commentaire:

Enregistrer un commentaire