I am using a timer interrupt to control various counters, the speed of the counter is controlled using the speeder variable which is defined above setup() so its global, however when i try redefining this within the loop function it doesn't do anything? I need to be able to redefine it several times and i'm unsure how to do it.
int speeder; // speed of counter set to 30 for bounce
void setup()
{
Serial.begin(9600);
pinMode(pirpin,INPUT);
digitalWrite(pirpin,LOW);
// initialize Timer1
cli(); // disable global interrupts
TCCR1A = 0; // set entire TCCR1A register to 0
TCCR1B = 0; // same for TCCR1B
// set compare match register to desired timer count:
//OCR1A = 15624; Original speed control
OCR1A = speeder;
// turn on CTC mode:
TCCR1B |= (1 << WGM12);
// Set CS10 and CS12 bits for 1024 prescaler:
TCCR1B |= (1 << CS10);
TCCR1B |= (1 << CS12);
// enable timer compare interrupt:
TIMSK1 |= (1 << OCIE1A);
calculate_ofsets();
// enable global interrupts:
sei();
}
void loop(){
if (digitalRead(pirpin) == HIGH){
speeder=30;
tracker ++;
// bounce = true;
}
else {
tracker = 0;
}
}