simulate inductive Crank shaft sensor vehicle

I'm currently involved in project and wrote some code (well mostly copied!) to simulate a 60-2 crankshaft position sensor. Basically the sketch should output 58 pulses, skip two, another 58 and so on. A pot on A0 provides a reference for pulse width and hence rpm. Could someone please have a look at the sketch and let me know if I have the pulse counts correct as i don't have a dso to verify the output?

/**
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);
}

/**
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.
}

/**
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);
delayMicroseconds(val);
}
triggerReference(val);
delayMicroseconds(val);
}

for(int i = 0; i <= 58; i++) {
triggerHigh(val);
delayMicroseconds(val);
}

How many iterations?

Please remember to use code tags when posting code

Surely it would be easier to have a loop 0 .. 59 to emit pulses. In the special case that the loop counter is 0 or 1, suppress the output of the pulses.

It would make more sense to me to move the delayMicroseconds() call from the for loop in loop() into triggerHigh(), so that triggerHigh() handled the complete cycle from low to high and back to low.

If you count, you have 121 calls to delayMicroseconds() - 59 in triggerHigh(), because it is called 59 times (for i = 0 to i = 58), 59 calls in the for loop, 2 calls in triggerReference(), plus the one after the call to triggerReference().

I would expect there to be 120 calls to delayMicroseconds().

val makes a really dumb name for a variable that is to hold the number of microseconds to wait between transitions.

Finally, you seem to expect digitalWrite() to complete in zero time. That is not a realistic expectation.