imapanda / arduino-nano

Having some fun with Arduino nano
MIT License
0 stars 0 forks source link

counter++ ? #1

Closed pierrebressy closed 2 years ago

pierrebressy commented 2 years ago

option 1 :

counter = 1-counter; // 0, 1, 0, 1 etc.

option 2 :

counter++;

in the loop function:

if(counter&1) { display_temp(); } else { display_humidity(); }

imapanda commented 2 years ago

option 1 :

counter = 1-counter; // 0, 1, 0, 1 etc.

option 2 :

counter++;

in the loop function:

if(counter&1) { display_temp(); }
else { display_humidity(); }
pierrebressy commented 2 years ago
void displayTemp() {
    puts("T=xxx °C");
    return;
}

void displayHumidity() {
    puts("H=XXX %");
    return;
}

int main(int argc, char const *argv[])
{
    void (*functions[2])(void) = {displayTemp,displayHumidity};

    int counter = 0;

    for (counter = 0; counter < 5;counter++) {
        functions[counter&1]();
    }
    return 0;
}
imapanda commented 2 years ago
void displayTemp() {
    puts("T=xxx °C");
    return;
}

void displayHumidity() {
    puts("H=XXX %");
    return;
}

int main(int argc, char const *argv[])
{
    void (*functions[2])(void) = {displayTemp,displayHumidity};

    int counter = 0;

    for (counter = 0; counter < 5;counter++) {
        functions[counter&1]();
    }
    return 0;
}

Used this solution