MORSE Code SOS Problem

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?

Is hard coding a morse message really a good solution?

Please post the code that doesn't work. You have only posted the code that does work, so there's not much we can say about that.

Why do you want to get rid of delay, in this case?

Honduras:
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.

Perhaps a problem with your LED circuit.

What happens if you direct the signal to the board LED on pin-13 with your code?

int ledPin = 13;

Do you then see the third 'dit' blinking on the pin-13 LED?

nilton61:
Is hard coding a morse message really a good solution?

I'm going through a tutorial book. Blame Michael McRoberts. :slight_smile:

arduinodlb:
Please post the code that doesn't work. You have only posted the code that does work, so there's not much we can say about that.

Ummm. That is the code that didn't work for me.

I thought about posting the code that did work, but blew it off.

Which delay?

jurs:
Perhaps a problem with your LED circuit.

What happens if you direct the signal to the board LED on pin-13 with your code?

int ledPin = 13;

Do you then see the third 'dit' blinking on the pin-13 LED?

This is the code that I got to work:

// Project SOS1

// LED connected to pin 10
int ledPin = 10;
int counter = 0;
int pin13 = 13;
int ditspace = 150;
int dahspace = 400;
int wordspace = 200;
int letterspace = 200;
int cycledelay = 2000;

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(ditspace);
     digitalWrite(ledPin, LOW);
     delay(ditspace);
    }
	
  delay(letterspace);
  
  for(counter = 0; counter < 3; counter ++)
    {
     digitalWrite(ledPin, HIGH);		
     delay(dahspace);
     digitalWrite(ledPin, LOW);
     delay(ditspace);
    }
       
  delay(letterspace);

  for(counter = 0; counter < 3; counter ++)
    {
     digitalWrite(ledPin, HIGH);
     delay(ditspace);
     digitalWrite(ledPin, LOW);
     delay(ditspace);
    }
      
  delay(cycledelay);
  
}

Honduras:
Ummm. That is the code that didn't work for me.

I thought about posting the code that did work, but blew it off.

Oh. My apologies. I misunderstood.

I must confess, that code looks pretty OK to me. Hmmmm.

Did you try using the on-board led with the original code that doesn't work? What was the result?

put in a delay before the second "for" loop and before the third "for" loop

your working example has those

How is the LED connected to pin 10? Is it active low, perchance?

Honduras:
Which delay?

The ones you said were "out of whack":

Honduras:
I know that the delays are out of whack, but I needed to be able to see what was going on.