Please help me, I am new to Arduino

Hi, This is my first post on this forum and i hope i posted this question in the correct section.
I recently discovered Arduino and have been playing with the Sparkfun inventors kit to get started.
I have familiarized myself with all of the included Arduino projects and i would now like to make an engine sensor simulator so i can bench test engine ECUs.
I need a simulator which will output a square wave signal to represent the crankshaft sensor. E.g. 60 teeth per revolution and 2 missing teeth for reference point. I also need to produce another square wave to represent the camshaft signal at half the speed of the crankshaft. I must be able to adjust the synchronisation of the signals 'against each other' to suit different car's computers. Another variant is that the crankshaft signal would have to be analog (as from a pulse generator which is also detecting teeth on a crankshaft sensor wheel with 2 teeth missing).
I know how to write the code to produce a simple square waveform and change (engine speed) but i'm not sure how to simulate the missing teeth.
I would be very grateful if anyone can help me as, like I said, i am new to this.

Thanks, Kooky :slight_smile:

I know how to write the code to produce a simple square waveform and change (engine speed) but i'm not sure how to simulate the missing teeth.

How are you generating this square wave?

The missing teeth would just not have the LOW to HIGH and HIGH to LOW transitions at appropriate times.

In other words, 58 times you do a "LOW to HIGH transition, wait a bit, HIGH to LOW transition, and wait a bit" cycle. Then, you do two "wait a bit, wait a bit" cycles (that don't have the LOW to HIGH and HIGH to LOW transitions).

Yes that's exactly what I'm asking. I can generate a simple loop of High / Low and I can use a pot to adjust delay time, but i just don't know how to do 58 cycles of high / low, then 2 cycles of low / low, then loop that whole sequence. Sorry if it sounds amateur, but like i said, it's all new to me.

I can generate a simple loop of High / Low and I can use a pot to adjust delay time, but i just don't know how to do 58 cycles of high / low, then 2 cycles of low / low, then loop that whole sequence.

void loop()
{
   int delayVal = analogRead(0); // Assume pot is connected to pin 0
   // Do 58 cycles of on for a while and off for a while
   for(int i=0; i<58; i++)
   {
      digitalWrite(4, HIGH); // Start square wave on pin 4;
      delay(delayVal);
      digitalWrite(4, LOW);
      delay(delayVal);
   }
   // Do 2 cycles of off for a while and off for a while
   for(int i=0; i<2; i++)
   {
      digitalWrite(4, LOW);
      delay(delayVal);
      digitalWrite(4, LOW);
      delay(delayVal);
   }
}

You need to search on while do and use a incerment operator :wink:
pseuodcode here

void loop()
count = ++count
while (count < 58 )
do 
{ 
// high low here
}
count = 0 ;
// low lwo here
}

The above is my way of doing things there may be eeven better ways of oding it :slight_smile:

Thanks PaulS and Newbie,
I will try both of your suggestions this weekend and let you know. I'll see if i can also introduce the second signal output (for the camshaft) and adjust the high low times as required.
Thanks again, These are the quickest responses I've ever had from any type of forum. Great work!

Kooky :slight_smile: