PickyBiker
Well-known member
The following sketch was set up to demonstrate the problem I have trying to use the IntervalTimer in my class. The member function the IntervalTimer points to, (Blink), is declared static. Once that is done, any attempt to address the class global value (val) from that member function generates the error, "invalid use of member 'Test::val' in static member function".
Of course if I don't declare the member function (Blink) static, I get the error, "invalid use of non-static member function".
If I don't access val, the code works fine.
How can I set this up to use the IntervalTimer in a class that won't prevent me from accessing class global values?
Of course if I don't declare the member function (Blink) static, I get the error, "invalid use of non-static member function".
If I don't access val, the code works fine.
How can I set this up to use the IntervalTimer in a class that won't prevent me from accessing class global values?
Code:
class Test
{
public:
IntervalTimer Timer;
int val;
Test()
{
pinMode(LED_BUILTIN, OUTPUT);
Timer.begin(Blink, 100000);
}
void On()
{
digitalWrite(LED_BUILTIN, LOW);
}
void Off()
{
digitalWrite(LED_BUILTIN, HIGH);
}
void SetBlinkSpeed(long desired_speed)
{
Timer.update(desired_speed);
}
static void Blink()
{
val = 20;
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
};
Test LED1;
void setup()
{
LED1.SetBlinkSpeed(25000);
}
void loop()
{
delay(2000);
LED1.SetBlinkSpeed(500000);
delay(2000);
LED1.SetBlinkSpeed(50000);
}