About Arduino Interrupts

Thank you ! Very good.
Also... try to modify my last code and put it in the correct form as you suggest.
If I see an example like that, it will make more sense to me.

you are calling BinaryRead() many times so what is in the String and what you compare could be different.

the code should just not use interrupts... May be something like this makes more sense

const byte ADC0808Pin = 2;
byte previousState;
bool doIWantThisOne = true;

void setup() {
  Serial.begin(115200);
  pinMode(ADC0808Pin, INPUT_PULLUP);
  previousState = digitalRead(ADC0808Pin);

  pinMode(13, INPUT);
  pinMode(12, INPUT);
  pinMode(11, INPUT);
  pinMode(10, INPUT);
}

void loop() {
  byte newState = digitalRead(ADC0808Pin);
  byte status = 0;      // we build a status byte with the 4 least significant bits from the 4 pins

  if (newState != previousState) {  // did we get a change?
    if (newState == HIGH) { // and was it a LOW to HIGH front ?
      if (doIWantThisOne) {
        status = 0;
        if (digitalRead(10) == HIGH) bitSet(status, 0);
        if (digitalRead(11) == HIGH) bitSet(status, 1);
        if (digitalRead(12) == HIGH) bitSet(status, 2);
        if (digitalRead(13) == HIGH) bitSet(status, 3);
      }

      if (status == 0b1111) { // seems this is a reset condition for you and you read again ???
        status = 0;
        if (digitalRead(10) == HIGH) bitSet(status, 0);
        if (digitalRead(11) == HIGH) bitSet(status, 1);
        if (digitalRead(12) == HIGH) bitSet(status, 2);
        if (digitalRead(13) == HIGH) bitSet(status, 3);
      }

      // so here what do you want to print out ?
      for (int i = 3; i >= 0; i--) Serial.write(bitRead(status, i) == 1 ? '1' : '0'); // the binary values of the 4 bytes?
      Serial.println(); // followed by a CR LF
      doIWantThisOne = false; // we will ignore it next time
    } else {
      doIWantThisOne = true;
    }
    previousState = newState;
  }
}

(I'm not to sure what you want to send and what's the business with all the '\r' and isReadOnce)

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