Esp32 interruption question

Bonjour, j'aimerais que toutes les secondes un octet soit lu si la commande "ok" est instruite dans le moniteur série, sinon c est le chiffre 23 qui se répète. J'ai un peu de a trouver le probleme.
un grand merci.

hw_timer_t * timer = NULL; // Declare a timer
byte essai = 0b00000000;
String instruct;




void IRAM_ATTR onTimer() { // Interrupt function

if (instruct = "ok") {
LireOctet(essai);
} else {
Serial.print(23);
}

}


void LireOctet(byte Vecteur) {
for (int ii = 0; ii < 8; ii++) {
        if (Vecteur & (B10000000 >> ii)) {
             Serial.print(1); //BitUn();
                                         }
        else {
            Serial.print(0); //BitZero(); //Serial.print(0);
             }
                   }
                   }




void setup() {
Serial.begin(115200);
timer = timerBegin (0, 80, true); // Initialization
timerAttachInterrupt (timer, &onTimer, true); // Call the interrupt function
timerAlarmWrite (timer,1000000, true); // Timerbegin parameter is 80MHz, here is 1000000 Meaning 1 second
timerAlarmEnable (timer); // Timer enables

// TimerDetAnterRupt (timer); // Close the timer
}


void loop() {
  if (Serial.available() )
{ 
      Serial.println(Serial.readString()); //Si un message a été reçu  faire ceci
      instruct=Serial.readString();
}
else
{
 instruct="rien";
}
}

Déjà je pense que tu peux simplifier ça par
Serial.print (Vecteur & (B10000000 >> ii));
Ça évite le if...

Ensuite, le test c'est ==

Merci bcp!!!!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.