(SOLVED) Trouble with not interrupting after sitting

Hello
I am having a problem with some code Iv written.
I'm relatively new to programming so copy paste is the name of the game at this point and I'm sure the fix will be something basic, iv tried all sorts of this to fix this but I'm at loss now.

So, What the code should do.
If the onOff is LOW it turns the whole process on.
then if the eye senses something it should run the portion of code between "iv seen something" and "doneski"
if at any point pin 12 goes HIGH it should run the interrupt function, turning label HIGH.
then after 100millis turn Label back to LOW.

Most of the time this all works a charm
BUT
If I turn the power on, leave it sitting for a few minutes the trigger pin 12, it won't do anything.
the same happens if I have triggered pin 12 then waited a few minutes then tried to trigger it again it doesn't work.
if i trigger every 20 or so seconds its fine.
Im using and Arduino UNO, IDE 1.6.12

any help appreciated
Thanks

here's my code

#include <Servo.h>
#include <EnableInterrupt.h>
#define ARDUINOPIN 12// 

const int onOff = 4;  //on Button
const int eye = 2;  //sensor that triggers start of main loop
const int blow = 5; //blow
const int next = 6; //lifts the blower
const int rotate = 7; //rotate
const int punch = 8; //push
const int label = 9; //
int servoPin = 11;  //servo attached here
int buttonState = 0; //variable for onOff button
int eyeState = 0; //variable for eye sensor
Servo Servo1;//servo assign
int interruptCounter = 0; //time since the last cycle
int labelling = 0; //variable, goes to 1 when cycling to make sure it wont cycle agin till time done.
int labelTime = 2200; // adjust this to change cycle downtime.

void interruptFunction() {     //interrupt from label start sensor, sends the signal to label but only if its been long enough since last cycle
  if (interruptCounter >= labelTime) {
    digitalWrite(label, HIGH);
    Serial.println("Start LABEL");
    interruptCounter = 0; //sets the timer to zero, starts the waiting process
    labelling = 1; //sets the labelling to 1 so that it can run the timer interrupt loop but only if its actually labelling
  }
}


void setup() {
  pinMode(onOff, INPUT_PULLUP);
  pinMode(eye, INPUT_PULLUP);
  pinMode(blow, OUTPUT);
  pinMode(next, OUTPUT);
  pinMode(rotate, OUTPUT);
  pinMode(punch, OUTPUT);
  pinMode(label, OUTPUT);
  digitalWrite(blow, HIGH);
  delay(100);
  digitalWrite(blow, LOW);
  Serial.begin(9600);
  Servo1.attach(servoPin);
  Serial.println("SETUP");
  Servo1.write(85);
  enableInterrupt(ARDUINOPIN, interruptFunction, CHANGE);
  OCR0A = 0xAF; //time interrupt stuff, copied from adafruit timer interrupts tutorial i think.
  TIMSK0 |= _BV(OCIE0A);
}
SIGNAL(TIMER0_COMPA_vect) //checks this once per milisecond, when true stops the label signal
{
  interruptCounter++;
  if (interruptCounter >= 100 && labelling == 1) {
    digitalWrite(label, LOW);
    Serial.println("Label signal sent");
    labelling = 0;
    Serial.print("Labelling");
    Serial.println(labelling);
  }
}
void loop() {
  buttonState = digitalRead(onOff);
  eyeState = digitalRead(eye);

  if (buttonState == LOW) {

    if (eyeState == LOW) {
      if (interruptCounter >= labelTime) { //hoping to fix the random 'no label after sitting issue...'
        interruptCounter = 0;
        labelling = 0;
      }
      Serial.println("Seen Something");
      digitalWrite(next, HIGH);
      Serial.println("Next");
      delay(40);
      digitalWrite(next, LOW);
      delay(500);
      digitalWrite(rotate, HIGH);
      Servo1.write(170);
      delay(300);
      Serial.print("Rotate");
      digitalWrite(punch, HIGH);
      Serial.println("Punch!!!");
      delay(150);
      digitalWrite(punch, LOW);
      delay(100);
      digitalWrite(rotate, LOW);
      Serial.println("Rot return");
      delay(200);
      Serial.println("Sol OTW");
      digitalWrite(blow, HIGH);
      Serial.println("Huff Puff");
      delay(300);
      digitalWrite(blow, LOW);
      Servo1.write(85);
      Serial.println("DONSKI");
    }
  }
}

I don't know if it applies in this case (timer interrupt) but the general rule is:

  1. No Serial.print() ing within interrupt service routines.

b. Variables used by the ISR are declared as volatile.

There are also a number of delay() statements. While waiting for the delay time to elapse the processor does nothing else - this is called blocking code. Blocking code is considered double plus ungood. See the thread Doing several things at the same time.

  OCR0A = 0xAF; //time interrupt stuff, copied from adafruit timer interrupts tutorial i think.

TIMSK0 |= _BV(OCIE0A);

Looks like you copied from someone else who doesn't know Arduinos either. Use the millis() function provided for this purpose.

Thanks for your help, still struggling though
I have tried playing around with a few things,
I deleted the Serial.print from the interrupt.
i tried playing around with timers instead of delays, couldn't get it working properly so I deleted everything in loop and I still have the same problem.

if I reset the arduino it going HIGH on pin 12 will make it run the interrupt
but
if it sits for a few minutes and then pin 12 goes HIGH nothing happens.
so my logic says the problem i was having wasn't caused buy the loop part, even though its not good code.
or am I overlooking something?
here's the code that still has the same problem.

#include <Servo.h>
#include <EnableInterrupt.h>
#define ARDUINOPIN 12// 

const int onOff = 4;  //on Button
const int eye = 2;  //sensor that triggers start of main loop
const int blow = 5; //blow
const int next = 6; //lifts the blower
const int rotate = 7; //rotate
const int punch = 8; //push
const int label = 9; //
int servoPin = 11;  //servo attached here
int buttonState = 0; //variable for onOff button
int eyeState = 0; //variable for eye sensor
Servo Servo1;//servo assign
int interruptCounter = 0; //time since the last cycle
int labelling = 0; //variable, goes to 1 when cycling to make sure it wont cycle agin till time done.
int labelTime = 2200; // adjust this to change cycle downtime.


void interruptFunction() {     //interrupt from label start sensor, sends the signal to label but only if its been long enough since last cycle
  if (interruptCounter >= labelTime) {
    digitalWrite(label, HIGH);
    interruptCounter = 0; //sets the timer to zero, starts the waiting process
    labelling = 1; //sets the labelling to 1 so that it can run the timer interrupt loop but only if its actually labelling
  }
}


void setup() {
  pinMode(onOff, INPUT_PULLUP);
  pinMode(eye, INPUT_PULLUP);
  pinMode(blow, OUTPUT);
  pinMode(next, OUTPUT);
  pinMode(rotate, OUTPUT);
  pinMode(punch, OUTPUT);
  pinMode(label, OUTPUT);
  digitalWrite(blow, HIGH);
  delay(100);
  digitalWrite(blow, LOW);
  Serial.begin(9600);
  Servo1.attach(servoPin);
  Serial.println("SETUP");
  Servo1.write(85);
  enableInterrupt(ARDUINOPIN, interruptFunction, CHANGE);
  OCR0A = 0xAF; //time interrupt stuff, copied from adafruit timer interrupts tutorial i think.
  TIMSK0 |= _BV(OCIE0A);
}
SIGNAL(TIMER0_COMPA_vect) //checks this once per milisecond, when true stops the label signal
{
  interruptCounter++;
  if (interruptCounter >= 100 && labelling == 1) {
    digitalWrite(label, LOW);
    labelling = 0;
  }
}
void loop() {
}
int interruptCounter = 0; //time since the last cycle

There's your problem. Look at the reference to find out how big an int can be. Now think about how many seconds you get when it's counting 1000 per second.

The solution is to use a long int, which can be abbreviated to just 'long'.

The "Arduino way" of doing this is to eliminate the timer interrupt completely. Just use millis() to count milliseconds. When you look at the online tutorials for that, you will see they all use long int too.

To add to what MorganS has said, a long can have a negative value. Since we can't have a negative time, we need to use a type that has only a positive value i.e. unsigned.

Sorry about the slow reply

Changing the int to unsigned long solved the whole problem
thanks!!

I'm sorry i know the whole delay thing is ugly, next thing on my list to learn is timing things without delay.

Heres the code that now works fine

#include <Servo.h>
#include <EnableInterrupt.h>
#define ARDUINOPIN 12// 

const int onOff = 4;  //on Button
const int eye = 2;  //sensor that triggers start of main loop
const int blow = 5; //blow
const int next = 6; //lifts the blower
const int rotate = 7; //rotate
const int punch = 8; //push
const int label = 9; //
int servoPin = 11;  //servo attached here
int buttonState = 0; //variable for onOff button
int eyeState = 0; //variable for eye sensor
Servo Servo1;//servo assign
unsigned long interruptCounter = 0; //time since the last cycle [color=red]Changing this from int to unsigned long fixed the issue![/color]
int labelling = 0; //variable, goes to 1 when cycling to make sure it wont cycle agin till time done.
int labelTime = 2200; // adjust this to change cycle downtime.

void interruptFunction() {     //interrupt from label start sensor, sends the signal to label but only if its been long enough since last cycle
  if (interruptCounter >= labelTime) {
    digitalWrite(label, HIGH);
    Serial.println("Start LABEL");
    interruptCounter = 0; //sets the timer to zero, starts the waiting process
    labelling = 1; //sets the labelling to 1 so that it can run the timer interrupt loop but only if its actually labelling
  }
}


void setup() {
  pinMode(onOff, INPUT_PULLUP);
  pinMode(eye, INPUT_PULLUP);
  pinMode(blow, OUTPUT);
  pinMode(next, OUTPUT);
  pinMode(rotate, OUTPUT);
  pinMode(punch, OUTPUT);
  pinMode(label, OUTPUT);
  digitalWrite(blow, HIGH);
  delay(100);
  digitalWrite(blow, LOW);
  Serial.begin(9600);
  Servo1.attach(servoPin);
  Serial.println("SETUP");
  Servo1.write(85);
  enableInterrupt(ARDUINOPIN, interruptFunction, CHANGE);
  OCR0A = 0xAF; //time interrupt stuff, copied from adafruit timer interrupts tutorial i think.
  TIMSK0 |= _BV(OCIE0A);
}
SIGNAL(TIMER0_COMPA_vect) //checks this once per milisecond, when true stops the label signal
{
  interruptCounter++;
  if (interruptCounter >= 100 && labelling == 1) {
    digitalWrite(label, LOW);
    Serial.println("Label signal sent");
    labelling = 0;
    Serial.print("Labelling");
    Serial.println(labelling);
  }
}
void loop() {
  buttonState = digitalRead(onOff);
  eyeState = digitalRead(eye);

  if (buttonState == LOW) {

    if (eyeState == LOW) {
      if (interruptCounter >= labelTime) { //hoping to fix the random 'no label after sitting issue...'
        interruptCounter = 0;
        labelling = 0;
      }
      Serial.println("Seen Something");
      digitalWrite(next, HIGH);
      Serial.println("Next");
      delay(40);
      digitalWrite(next, LOW);
      delay(500);
      digitalWrite(rotate, HIGH);
      Servo1.write(170);
      delay(300);
      Serial.print("Rotate");
      digitalWrite(punch, HIGH);
      Serial.println("Punch!!!");
      delay(150);
      digitalWrite(punch, LOW);
      delay(100);
      digitalWrite(rotate, LOW);
      Serial.println("Rot return");
      delay(200);
      Serial.println("Sol OTW");
      digitalWrite(blow, HIGH);
      Serial.println("Huff Puff");
      delay(300);
      digitalWrite(blow, LOW);
      Servo1.write(85);
      Serial.println("DONSKI");
    }
  }
}

Good to hear you fixed it. Another thing you might want to look at is your interrupt routine. Generally it is a bad idea to do anything that takes too long within an interrupt routine. Serial printing is one of those things. Here is some reading on interrupts. I hope it is of use to you.