#include <TimerOne.h>
#include <Streaming.h>
volatile unsigned long injector = 0;
volatile unsigned long injector_counter = 0;
volatile unsigned long pulse_time_counter = 0;
volatile unsigned long speed_sensor = 0;
volatile unsigned long measurement_time = 0;
volatile unsigned long speed_sensor_counter = 0;
int printTime = 1;
unsigned long ltime, time; //time variables
unsigned long lastTime;
int check = 0;
void setup()
{
Serial.begin(115200);
pinMode(13, OUTPUT);
Timer1.initialize(1000000); // set a timer of length 100000 microseconds (or 0.1 sec - or 10Hz => the led will blink 5 times, 5 cycles of on-and-off, per second)
Timer1.attachInterrupt( timerIsr ); // attach the service routine here
}
void loop()
{
if (check == 1) {
Serial << injector_counter << endl;
pulse_time_counter = injector_counter = speed_sensor_counter = measurement_time = 0;
}
check = 0;
injector = pulseIn(2, HIGH);
// speed_sensor = pulseIn(3, HIGH);
if (injector != 0)
{
pulse_time_counter = pulse_time_counter + injector;
injector_counter++;
}
if (speed_sensor != 0)
{
speed_sensor_counter++;
}
}
void timerIsr()
{
check = 1;
digitalWrite( 13, digitalRead( 13 ) ^ 1 );
}
As it looks now?
Is there a way to measure whether the Loop function equal to abide with me one second?