Error compiling FlexiTimer2 library

Hello folks.

I need some help with the library I´m trying to build.

In this project, I´m using the FlexiTimer2 library to turn off a fuel pump in a timed manner. (http://playground.arduino.cc/Main/FlexiTimer2)
I have tried to fix this code in so many ways, but I could not find my mistake.
I’m posting the code I think is closer to being correct.

This is the error I’m getting:
…\Arduino\arduino-1.0.3\libraries\Injector\Injector.cpp: In constructor ‘Injector::Injector(int, int, int, int)’:
…\Arduino\arduino-1.0.3\libraries\Injector\Injector.cpp:25: error: ‘FlexiTimer2’ has not been declared
…\Arduino\arduino-1.0.3\libraries\Injector\Injector.cpp:26: error: ‘FlexiTimer2’ has not been declared

Arduino Code

#include <Injector.h>

int pushButton = 5;
int relayPin = 6;

Injector injector1(relayPin, 750, 3, 60);

void setup() {
  Serial.begin(115200);
  
  pinMode(pushButton, INPUT);
  digitalWrite(pushButton,HIGH);

}

void loop() {
  while(digitalRead(pushButton)==LOW)
  {    
    Serial.write("Button pressed\n");
    injector1.inject();    
    delay(1000);
  }
  delay (50);
}

Injector.h

#ifndef Injector_h
#define Injector_h

#include "Arduino.h"
#include <FlexiTimer2\FlexiTimer2.h>

class Injector
{
  public:
    Injector(int outPin, int injectionDuration, int maxInjectsPerCycle, int cycleInterval);
	void inject();
	void setAlarm(bool alarmState);
	
  private:
	void stopInjection();
  
	int _outPin;
	int _injectionDuration;
	int _maxInjectsPerCycle;
	int _cycleInterval;
	
	long _cycleStart;
	long _injectionThreshold;
	int _injects;
	
	bool _pumpOn;	
	bool _alarmOff;
};

#endif

Injector.cpp

#include <Injector.h>
#include <FlexiTimer2\FlexiTimer2.h>

Injector::Injector(int outPin, int injectionDuration, int maxInjectsPerCycle, int cycleInterval)
{
	_outPin = outPin;
	_injectionDuration = injectionDuration;
	_maxInjectsPerCycle = maxInjectsPerCycle;
	_cycleInterval = cycleInterval;
	
	_alarmOff = false;
	_pumpOn = false;
	
	pinMode(_outPin, OUTPUT);
	digitalWrite(_outPin, LOW);
	
	_injects = 0;
	
	FlexiTimer2::set(50, stopInjection);
	FlexiTimer2::start();
	
}

void Injector::inject()
{
	if ( _alarmOff )
		return;
	
	if (millis() > ( _cycleStart + _cycleInterval) || _injects == 0 )
	{
		_cycleStart = millis();
		_injects = 0;
	}

	if (_injects < _maxInjectsPerCycle)
	{
		_injectionThreshold = millis() + _injectionDuration;
		_injects++;
		_pumpOn = true;
		digitalWrite(_outPin, HIGH);
	}
}

void Injector::stopInjection()
{
	if ( millis() > _injectionThreshold && _pumpOn )
	{
		digitalWrite(_outPin, LOW);
		_pumpOn = false;
	}
}

void Injector::setAlarm(bool alarmState)
{
	_alarmOff = alarmState;
}

Thanks!

Like too many other people, you are trying to hide the use of the FlexiTimer2 library from the sketch. You can NOT do that.

PaulS, thanks a lot.

I already had a suspicion that I could only use one instance of FlexiTimer2, given that Arduino UNO has only 2 timers, and timer1 is already used internally.

Can you give me the name of the property or design property that allows a developer to protect it´s class like was done in FlexiTimer2? I would like to learn more about this.

Thanks.

Can you give me the name of the property or design property that allows a developer to protect it´s class like was done in FlexiTimer2?

I guess not, since I don't understand what this means. The FlexiTimer2 class is not protected in any way. You have the source code. You can change the class in any way you want.

I already had a suspicion that I could only use one instance of FlexiTimer2, given that Arduino UNO has only 2 timers, and timer1 is already used internally.

I'm not sure that you are limited to one instance.

If you want the separate instances to fire at different times, you might have problems. But if one is supposed to fire on a multiple of the other, there should be no problem. By this, I mean that if you need one function to fire every 37 milliseconds, and the other to fire every 13, you could run into problems. But, if one is to fire every 10 milliseconds, and the other is to fire every 30 milliseconds, then one timer can trigger both events. The 30 millisecond event simply ignores 2 out of 3 calls.