japie:
Hello there, got the basic timer code working:#include "TimerOne.h"
#include "TimerThree.h"
int ledPin = 13;
volatile int state = LOW;
volatile int InjectionCycle1 = false;
void setup()
{
pinMode(ledPin, OUTPUT);
attachInterrupt(0, Inject1, RISING); // interrupt 0 = pin 2
Timer1.initialize(1000000);
Timer1.stop(); //stop the counter
Timer1.disablePwm(9); // disables PWM on pin 9
Timer1.disablePwm(10); // disables PWM on pin 10
Serial.begin(9600);
}
void loop()
{
}
void Inject1()
{
if (InjectionCycle1 == false)
{
Serial.print("start injection cycle: ");
Serial.println (millis());
InjectionCycle1 = true;
Timer1.setPeriod(1000000);
Timer1.attachInterrupt(OpenInjector1);
}
}
void OpenInjector1()
{
if (InjectionCycle1 == true)
{
Serial.print("open injector: ");
Serial.println (millis());
digitalWrite(ledPin, HIGH);
Timer1.stop();
Timer1.detachInterrupt();
Timer1.setPeriod(2000000);
Timer1.attachInterrupt(CloseInjector1);
}
}
void CloseInjector1()
{
if (InjectionCycle1 == true)
{
Serial.print("close injector: ");
Serial.println (millis());
Serial.println ("");
digitalWrite(ledPin, LOW);
InjectionCycle1 = false;
Timer1.stop();
Timer1.detachInterrupt();
}
}
Tested this and it works as expected, next step integrate all other stuff, will port when I have it complete. In this setup the timer replace delay. (and is not stalling the loop like delay) edited since in first instance I used Timer1 and Timer3 both for both delays: Using one timer for the cycle works also good so I can use Timer1 for cylinders 1 and 4 and Timer3 for cylinders 2 and 3. Since the firing order is 1-3-4-2 there is 180 crank degree extra time between interrupt firing cycles, better would be a per cylinder dedicated timer but rewriting the Timer1 code for the extra timers on the mega is out off my league...
When I want to run this, I get: Timer1 was not declared in this scope.
I'm very new to arduino and elektronics, sorry.
And Japie I found more stuf injectors and pump. I even have a pump and four of the six injectors, aextra Uno an a Mega to start with.
Panther95