My Code:
//Constants which won't change:
const int IP1 = 2; // use your pin numbers here: This is my start button
const int IP2 = 3; // This is my counter input
const int RELAY = 13; // This is my injector enable output
// Variables will change:
int N_PULSES = 100; // This are number of injections allowed
void setup () {
pinMode (IP1, INPUT);
pinMode (IP2, INPUT);
pinMode (RELAY, OUTPUT);
digitalWrite (RELAY, LOW);
}
void loop () {
// wait for button to be pressed
// NOTE: input doesn't really need to be debounced
// assumes pull down resistor on switch
while (digitalRead(IP1) != HIGH) {};
// relay activated
digitalWrite (RELAY, HIGH);
for (int i = 0; i < N_PULSES; i++) {
// just use pulseIn() to count the pulses
// don't care about the pulse width
pulseIn (IP2, HIGH);
}
// relay deactivated
digitalWrite (RELAY, LOW);
// assumes the one-shot on IP1 is set to < the time N_PULSES takes
// if not then wait here for IP1 to go LOW again ie. button released
//FOR THIS SETUP, AFTER 20 COUNTS OUTPUT 13 IS RESET, IS THIS BINAIR CODED?
}