It is corect MORSE code

Please, if someone check if this is right. Or what can be read from the flashing diodes.

CODE:

SRECNO NOVO LETO (slovin)
Happy new year (english)

//MORSE  CODE

// Za novoletne lučke, direktno upravljanje LED diod
//  Miran Rajšp
//28. 12. 2014

// the setup function runs once when you press reset or power the board
void setup() {
 // initialize digital pin 13 as an output.
 pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() 

     {

 delay(2250);
 
  dot(); dot(); dot();// S
 dot(); dot(); // presledek
 
  dot(); dash(); dot();// R
 dot(); dot(); // presledek
 
 dot(); //E
 dot();dot();//presledek
 
 dash(); dot();dash(); dot();//C
 dot();dot();//presledek
 
 dash(); dot();//N
 dot();dot();//presledek
 
 dash(); dash(); dash();//O
 dot();dot();//presledek
 
 
 dot();dot();dot();//presledek med besedami
 
 
 dash(); dot();//N
 dot();dot();//presledek
 
 dash(); dash(); dash();//O
 dot();dot();//presledek
 
 
 dot(); dot(); dot(); dash(); // V
 dot();dot();//presledek
 
 dash(); dash(); dash();//O
 dot();dot();//presledek
 
 dot();dot();dot();//presledek med besedami
 
 
 dot(); dash(); dot(); dot(); // L
 dot();dot();//presledek
 
 dot();//E
 dot();dot();//presledek
 
 dash();//T
 dot();dot();//presledek
 
 dash(); dash(); dash();//O
 dot();dot();//presledek
 
 
 dot();dot();dot();//presledek med besedami
 
 dash(); dot(); dash(); dot(); // C
 dot();dot();//presledek
 
 dot(); dash();// A
 dot();dot();//presledek
 
 dot(); dash(); dot(); dot(); // L
 dot();dot();//presledek
 
 dot(); dash(); dot(); dot(); // L
 dot();dot();//presledek
 
 dot();dot();dot();//presledek med besedami
 
 dash(); dash(); dash(); dash(); dash();//0  (nič)
 dot();dot();//presledek
 
 dot();dot();dot();dot();dash(); // 4
 dot();dot();//presledek
 
 dot();dash();dash();dash();dash(); // 1 (ena)
 dot();dot();//presledek
 
 dot();dot();dash();dash();dash(); // 2  (dva)
 dot();dot();//presledek
 
 dot();dot();dot();dash();dash(); // 3   (tri)
 dot();dot();//presledek
 
 dash();dot();dot();dot();dot(); // 6 (šest)
 dot();dot();//presledek
 
 dot();dot();dash();dash();dash(); // 2  (dva)
 dot();dot();//presledek
 
 dash();dash();dash();dash();dot(); // 9  (devet)
 dot();dot();//presledek
 
 dash();dot();dot();dot();dot(); // 6 (šest)
 dot();dot();//presledek
 
 
 
 
 
 
 delay (5000);

 
 
}

void dot()
{
 analogWrite(13, 200);
 delay(250);
 analogWrite(13, 0);
 delay(250);  
}

void dash()
{
 analogWrite(13, 200);
 delay(1000);
 analogWrite(13, 0);
 delay(250);
}

Which Arduino is this?

Normally you would use digitalWrite for pin 13 on a Uno.

You might find this helpful:

http://forum.arduino.cc/index.php?topic=277631.msg1952967#msg1952967

I can't read anything from the LEDs because you aren't sending the morse code properly (changing analogWrite to digitalWrite is the correct way to send to the LED but doesn't help).
You need to read up on how to send Morse code properly. A dash is three times the length of a dot - not four times and there needs to be a short pause between each letter. As it is, it is unreadable.

Also, read How to post code properly and then fix up your message with tags.

Pete

Sorry for the wrongly sent to the question!

AnalogWrite I used, because of the restrictions 40 mA!

"A dash is three times the length of a dot - not four times". This is the solution for me.
Thanks so much for all the advice

zacetnik:
Sorry for the wrongly sent to the question!

AnalogWrite I used, because of the restrictions 40 mA!

"A dash is three times the length of a dot - not four times". This is the solution for me.
Thanks so much for all the advice

Are you hooking up an LED directly to the arduino pin down to ground?
If so, using AnalogWrite does not get around the 40mA limit. This is because AnalogWrite does not output a true analog waveform. Instead, it uses PWM. If you hooked it up to an oscilloscope, you would see a 5v output rapidly turning on and off to simulate a voltage less than 5v. Thus, during those brief periods where it is high, you are still putting 5v on that pin and thus the LED will be pulling more than 40mA.

You must use a current limiting resistor and I would highly recommend using digitalWrite.

Cosford is correct.

Using analogWrite does not in any way remove the restrictions on the amount of current.

You should certainly be using a current-limiting resistor and possibly a driver transistor as well.

This is the solution for me.

Getting the dot-dash ratio correct is not going to make what your program is sending any more readable than it was before.

Pete

I would HIGHLY recommend that some of you "experts" read the OP AGAIN before you go off to the left field and start giving irrelevant advises.

To the OP - replace your character pause with simple 3x dot delay() (function) and your word pause with simple 5X dot delay(). And if you use digitalWrite the LED will be brighter.
--... ...-- -.. . .- .- --... . .--- ...-.- ..

Thanks Vaclav, however I don't think it is irrelevant to suggest that the OP uses resistors, or he will destroy his processor.

Thanks so much for all the advice, I will follow.
I did the measurements of the maximum electric current.
In the next project I do this with tiristorjem.
i buy book of Simon Monk.

How did you measure the current of a PWM?

Shpaget:
How did you measure the current of a PWM?

With analog multimeter

Yeah, that's not going to work.
When dealing with PWM (and analogWrite is PWM) you get periodic 5V and 0V, switching rapidly. Analog multimeter is not fast enough to catch the these fast switchings and shows some average value, not maximum current that is drawn during the time when 5V is being applied.

There are several spacing patterns that are used when sending Morse code. Most use the spacing mentioned earlier, but alternatives exist (e.g., Farnsworth encoding). To make it easier for you to change the timing delays, I'd suggest something like the following:

//MORSE  CODE

// Za novoletne lučke, direktno upravljanje LED diod
//  Miran Rajšp
//28. 12. 2014

#define DOTDELAY  250
#define DASHDELAY (DOTDELAY * 3)
#define CHARSPACE (DOTDELAY * 4)
#define WORDSPACE (DOTDELAY * 7)

void setup() {
  pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {

  dot(); dot(); dot(); dot(); pause(CHARSPACE);  // H
  dot(); pause(CHARSPACE);                       // E
  dot(); dash(); dot(); dot(); pause(CHARSPACE); // L
  dot(); dash(); dot(); dot(); pause(CHARSPACE); // L
  dash(); dash(); dash();                        // O
  pause(WORDSPACE);
}

void pause(int period)
{
  digitalWrite(13, LOW);
  delay(period);
}
void dot()
{
  digitalWrite(13, HIGH);
  delay(DOTDELAY);
  digitalWrite(13, LOW);
  delay(DOTDELAY);
}

void dash()
{
  digitalWrite(13, HIGH);
  delay(DASHDELAY);
  digitalWrite(13, LOW);
  delay(DOTDELAY);
}

Using symbolic constants will make it easier to read and change your code.

W8TEE

All of the correct timing is in the source code for Magic Morse.

        elements	WPM	tElements	mS / element
        50	          5	  250	          240
        50	         10	  500	          120
        50	         15	  750	           80
        50	         20	 1000	           60
        50	         25	 1250	           48
        50	         30	 1500	           40
        50	         35	 1750	           34
        50	         40	 2000	           30
        50	         45	 2250	           27
        50	         50	 2500	           24

Snippet:

char PARIS(byte Letter)
{
  switch(Letter)
    {
    case 0:      // P
      tone(toneOutPin, toneHz); delay(DITmS);  // <dit>
      noTone(toneOutPin); delay(DITmS);        // <quiet>
      tone(toneOutPin,toneHz); delay(DAHmS);   // <dah>
      noTone(toneOutPin); delay(DITmS);        // <quiet>
      tone(toneOutPin,toneHz); delay(DAHmS);   // <dah>
      noTone(toneOutPin); delay(DITmS);        // <quiet>
      tone(toneOutPin, toneHz); delay(DITmS);  // <dit>
      noTone(toneOutPin); delay(DITmS);        // <quiet>
      noTone(toneOutPin); delay(DITmS);        // <quiet>
      noTone(toneOutPin); delay(DITmS);        // <quiet>
      return 'P';
    case 1:      // A
      tone(toneOutPin, toneHz); delay(DITmS);  // <dit>
      noTone(toneOutPin); delay(DITmS);        // <quiet>
      tone(toneOutPin,toneHz); delay(DAHmS);   // <dah>
      noTone(toneOutPin); delay(DITmS);        // <quiet>
      noTone(toneOutPin); delay(DITmS);        // <quiet>
      noTone(toneOutPin); delay(DITmS);        // <quiet>
      return 'A';
    case 2:      // R
      tone(toneOutPin, toneHz); delay(DITmS);  // <dit>
      noTone(toneOutPin); delay(DITmS);        // <quiet>
      tone(toneOutPin,toneHz); delay(DAHmS);   // <dah>
      noTone(toneOutPin); delay(DITmS);        // <quiet>
      tone(toneOutPin, toneHz); delay(DITmS);  // <dit>
      noTone(toneOutPin); delay(DITmS);        // <quiet>
      noTone(toneOutPin); delay(DITmS);        // <quiet>
      noTone(toneOutPin); delay(DITmS);        // <quiet>
      return 'R';
    case 3:      // I
      tone(toneOutPin, toneHz); delay(DITmS);  // <dit>
      noTone(toneOutPin); delay(DITmS);        // <quiet>
      tone(toneOutPin, toneHz); delay(DITmS);  // <dit>
      noTone(toneOutPin); delay(DITmS);        // <quiet>
      noTone(toneOutPin); delay(DITmS);        // <quiet>
      noTone(toneOutPin); delay(DITmS);        // <quiet>
      return 'I';
    case 4:      //S
      tone(toneOutPin, toneHz); delay(DITmS);  // <dit>
      noTone(toneOutPin); delay(DITmS);        // <quiet>
      tone(toneOutPin, toneHz); delay(DITmS);  // <dit>
      noTone(toneOutPin); delay(DITmS);        // <quiet>
      tone(toneOutPin, toneHz); delay(DITmS);  // <dit>
      noTone(toneOutPin);
      return 'S';
    }
}


void Paris( void )
{
  Serial << (F("WPM: "))            << WPM        << endl;
  if (!digitalRead(VerbosePin)) STATUS();
  Serial << (F("Printing PARIS on LCD display:")) << endl;
  for (int q = 0; q < 5;q++)
    { SendMorseLCD(PARIS(q)); }
  Serial << endl;
}

Ray

Thanks again econjack for such a simple and transparent codo.
This was my first program. Now I've learned a lot, it will be easier to work.

the next project will be more difficult. To turn on the pumps in the central heating, depending on the temperature.

zacetnik:
Thanks again econjack for such a simple and transparent codo.
This was my first program. Now I've learned a lot, it will be easier to work.

the next project will be more difficult. To turn on the pumps in the central heating, depending on the temperature.

If you are not a licensed electrician, you may wish to exercise caution - not only for the obvious high voltage that exists in the AC mains, but also that your actions may have liability with building insurance, etc. Anyone can wire in a relay, but not everyone should.

Just saying...

Ray

"mrburnette"
My primary profession is it "electrician".
In my day, there has never been such a thing. Electronics I do not close. I have a lot of work with high voltage AC.
such warnings are always right here. Thank You Very Much. Arduino is a new hobby for me.
I want to learn to program for doing this kind of thing.