Having trouble with the serial input

So, I’m writing a thing I want to use to monitor incoming messages (yes, terribly exciting, I know!) Problem is, when I hit the button (which is hooked up to an interrupt that runs a function designed to shut off the LEDs) it just temporarily interrupts the blinking. What’s going on here?

const int ledPinSkype = 8;
const int ledPinIRC = 4;
const int swiPinIRQ = 0;
const int blkFrq = 100;
int signal;
long blinkers = 0;

void setup() {
  Serial.begin(9600);
  pinMode(ledPinSkype, OUTPUT);
  pinMode(ledPinIRC, OUTPUT);
  pinMode(swiPinIRQ, INPUT);
  attachInterrupt(swiPinIRQ, resetBlink, RISING);
}

void loop() {
  SerialMonitor();
}

void SerialMonitor() { // if there's something from the serial, blink the appropriate lights
  int incoming = 0;
  if (Serial.available() > 0) {
    incoming = Serial.read();
    Serial.println(incoming);
    blinkLight(incoming);
  }
  
}

void blinkLight(int signal) { // controls the blinking of the lights
  if (signal == 48) {
    while (blinkers < 10000){
      digitalWrite(ledPinSkype, HIGH);
      delay(blkFrq);
      digitalWrite(ledPinSkype, LOW);
      delay(blkFrq);
      blinkers++;
    }
  }
  if (signal == 49) {
    while (blinkers < 10000) {
      digitalWrite(ledPinIRC, HIGH);
      delay(blkFrq);
      digitalWrite(ledPinIRC, LOW);
      delay(blkFrq);
    }
  }
}

void resetBlink() { // this SHOULD be resetting the blinking.  Right now, it just... temporarily interrupts it.  Harhar.
  digitalWrite(ledPinSkype, LOW);
  digitalWrite(ledPinIRC, LOW);
  Serial.end();
  Serial.begin(9600);
  loop();
}

Any help would be appreciated! :slight_smile:

This may not be your bug, but I can't see where blinkers gets reset to zero after being pushed to 10000.

-br

I had that in there originally. However, even putting it back in it STILL doesn't help fix this issue. This is very very frustrating for me.

I think I may have come across the issue, though, or at least something that may help uncover the issue. I changed the blinkers threshold to 50, so it shuts off after a few seconds of blinking. Now, once it's shut off, it should allow for input from the serial monitor again, but it doesn't...

You should NEVER call loop(). Period.

  if (signal == 49) {
    while (blinkers < 10000) {
      digitalWrite(ledPinIRC, HIGH);
      delay(blkFrq);
      digitalWrite(ledPinIRC, LOW);
      delay(blkFrq);
    }

If a 49 comes in (why the heck aren’t you making it easy and testing for ‘1’?), this is an infinite loop. Hardly a good idea.

What is it you are attempting to do, anyway? What is generating the interrupt? Why?

This is supposed to be a visual notifier for Skype and my IRC client.

Once I removed the blinking, everything worked fine, oddly enough. The button that generates the interrupt to turn the LEDs off worked absolutely fine. Any idea why the blinking messed it up?