Counting 0 through 58, inclusive, gives you 59 counts:
for(int i = 0; i <= 58; i++) {
Typically you would count to 58 by counting 0 through 57, inclusive:
for(int i = 0; i < 58; i++) {
If the two missing pulses are supposed to be the same length as the 58 other pulses you need to do FOUR delays instead of THREE (two in the triggerReference() function and one after).
I would put all the delays in the functions:
/**
crank signal simulator
*/
#define PULSE_PIN 10
void setup() {
pinMode(PULSE_PIN, OUTPUT);
}
/**
Simulate the high of a tooth on a
reluctor wheel
*/
void triggerHigh(int duration) {
digitalWrite(PULSE_PIN, HIGH);
delayMicroseconds(duration);
digitalWrite(PULSE_PIN, LOW);
delayMicroseconds(val);
}
/**
Simulate the reference marker on a
reluctor wheel
*/
void triggerReference(int duration) {
// pin should be low already
delayMicroseconds(duration);
delayMicroseconds(duration); // two delays for two missing pulses.
delayMicroseconds(duration);
delayMicroseconds(duration); // two delays for two missing pulses.
}
/**
Simulates a 58 tooth reluctor wheel
with a 2 tooth reference
*/
void loop(){
int val = analogRead(0);
val = map(val, 0, 1023, 100, 3500);
for(int i = 0; i <= 58; i++) {
triggerHigh(val);
}
triggerReference(val);
}