Creating interrupts? - Solved

I at the moment trying to control when my interrupt should be called, by changing the TOP counter value of the timer1.

Problem is though that it doesn't seem like the interrupt react as i want it to. It doesn't seem like it change the top value, it keeps the same topvalue for some reason.

#include "test.h"

volatile int step_count = 1;

test::test()
{

  pinMode(LED_BUILTIN, OUTPUT);
  Timer1.initialize(1000000);
  Timer1.attachInterrupt(callback);
}

long period_used;
bool value = true;
static void test::callback()
{
  if(value == true)
  {
      period_used = 5000000;
      Timer1.setPeriod(period_used);
      value = false;

  }
  if(value ==false)
  {
    period_used = 1000000;
    Timer1.setPeriod(period_used);
    value = true;
  }

}


void test::test_()
{
  
  Serial.print("period: ");
  Serial.println(period_used);
  Serial.print('\n');
  Serial.print("value: ");
  Serial.println(value);
}

The serial output from test_() shows that period_used is always 1000000 and never become the other
value, and the bool value never changes value.

I am using the timer1 library available from arduino to interface with the timer1.

What could be wrong here?

Look carefully at your callback. You set it very briefly to 5000000 and then set it right back to 1000000 before you exit that function.

Did you mean for that second if in callback to be an else?

long period_used = 0;
bool value = true;
static void test::callback()
{
  if(value == true)
  { 
      period_used = 5000000;
      Timer1.setPeriod(period_used);
      value != value;

  }
  else
  {
    period_used = 1000000;
    Timer1.setPeriod(period_used);
    value != value;
  }
}

This does the same..

It shouldn't. In the old code the second if was always true. Now it only sets period_used to 1000000 when value is initially false.

if i change value to initially be false i get this on the serial.

value: 0
period: 1000000

value: 0
period: 1000000

value: 0
period: 1000000

value != value;

That's a pretty useless comparison

Did you mean

value = !value;

thats indeed a pretty useless comparison.
Just caught it myself.