I would have broken it up into 2 functions, but not sure that would help.
Here's the code:
// Project SOS1
// LED connected to pin 10
int ledPin = 10;
int counter = 0;
int pin13 = 13;
void setup()
{
// Set the pin as an output
pinMode(ledPin, OUTPUT);
pinMode(pin13, OUTPUT);
digitalWrite(pin13, LOW);
}
void loop()
{
// 3 dits
for(counter = 0; counter < 3; counter ++)
{
digitalWrite(ledPin, HIGH);
delay(150);
digitalWrite(ledPin, LOW);
delay(400);
}
for (counter = 0; counter < 3; counter ++)
{
digitalWrite(ledPin, HIGH);
delay(400);
digitalWrite(ledPin, LOW);
delay(400);
}
for(counter = 0; counter < 3; counter ++)
{
digitalWrite(ledPin, HIGH);
delay(150);
digitalWrite(ledPin, LOW);
delay(400);
}
delay(5000);
}
I know that the delays are out of whack, but I needed to be able to see what was going on.
I put in the program in the book, and it looked OK, but when I ran it, I got dit dit dit, pause. dah dah dah, dit dit. No third dit.
I looked at the code very closely, took out some extraneous 'delays' and tried again. No change.
After fiddling around for a while, I decided to remove the last 'dit dit dit' section. (Should have commented it out. Oh well.)
After that, I got dit dit dit dah dah. No third dah.
So I increased the delays for the first time and got 'dit dit dit dah dah dah'. What I was expecting to see, so I put yjr second 'dit' procedure back in. 'dit dit dit dah dah dah dit dit'.
So I increased all the delays. (I think) and it worked fine. I'm using a Uno attached to an 8 core AMD system, so I would be depressed to find out that either the Uno, or the computer couldn't keep up.
Does anyone have any thoughts on this?