Loop only plays once

Hi,

I want to send morse to different led’s
To do this i found a morse example and it runs great on 2 led’s with different codes

But it only plays once a time, i would like it to play continuous
My knowledge is to low to solve this.

The sketch is :

/*
 * morse_example_avr.ino - Simple example of using the Etherkit Morse library
 *                         on an AVR-based Arduino
 *
 * Copyright (C) 2018 Jason Milldrum <milldrum@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

 #include <SimpleTimer.h>
 #include <Morse.h>

int ledPin1 = 13;
int ledPin2 = 12;

 // Class declaration
 Morse morse1(ledPin1, 15);
 Morse morse2(ledPin2, 15);
 
 SimpleTimer timer;

 // a function to be executed periodically
 void repeatMe()
 {
   morse1.update();
   morse2.update();
 }

 void setup()
 {
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  
   timer.setInterval(4, repeatMe);

   delay(1000);
   morse1.send("1");
   morse2.send("2");
 }

 void loop() {
   timer.run();
   
 }

inside your repeatMe() function, you update the progress of the morse code. When it is done transmitting the message, there is nothing more to do but your function is still being called.

You need to check if Morse.busy is true or false and send the message again when it becomes false.

I'll leave the actual code writing to you....

Thanks!
But how do i check if still busy?
Does that needs to be done in the loop?

If (Morse.busy ==false ) {

Update again?
}

Like this??

For one you need to put your "repeatMe();" method in your loop like this:

void loop() {
   timer.run();
   repeatMe();
 }

I hope this helps,

-- DH

DH12043:
For one you need to put your "repeatMe();" method in your loop like this:

void loop() {

timer.run();
  repeatMe();
}





I hope this helps,

-- DH

No, repeatMe is being called by the stupid timer class. It's not being called explicitly from loop.

OK, well, that doesn’t make a whole lot of sense.

DH12043:
OK, well, that doesn't make a whole lot of sense.

Look up that SimpleTimer class he is using.

jep repeatMe(); is not working....

tried also

if ( Morse.busy == false ) {

that gives an error

any other tips to get this repeating?

rogierv:
that gives an error

And you didn't think that the error message was important?

O sorry but because it was mentioned that it was not gonna work i thought it is clear that it gives an error.

I tried morse.busy but without result too

Think i am gonna buy 5 more arduinos and use one arduino for each led to make it work. I cannot find out to make it work this way.

Thanks for your help and ideas!!

Think i am gonna buy 5 more arduinos

That would be foolish. Why don't you let us help you? But you gotta give us a chance. "There was an error" isn't something I can help with. It's just an observation. If you give me a complete piece of code and a complete error message then I can maybe tell you how to fix.

rogierv:
Thanks!
But how do i check if still busy?
Does that needs to be done in the loop?

If (Morse.busy ==false ) {

Update again?
}

Like this??

'Morse' is not the variable you are declaring. Your variable names are morse1 and morse2. You need to check both of them for not being busy and resend or do them independently.

if ( morse1.busy == false ) { morse1.send("1 again"); }
if ( morse2.busy == false ) { morse2.send("2 again"); }

Delta_G:
That would be foolish. Why don’t you let us help you? But you gotta give us a chance. “There was an error” isn’t something I can help with. It’s just an observation. If you give me a complete piece of code and a complete error message then I can maybe tell you how to fix.

agree :wink:

but don’t know how to fix it.
The complete code is :

 #include <SimpleTimer.h>
 #include <Morse.h>

int ledPin1 = 13;
int ledPin2 = 12;

 // Class declaration
 Morse morse1(ledPin1, 15);
 Morse morse2(ledPin2, 15);
 
 SimpleTimer timer;

 // a function to be executed periodically
 void repeatMe()
 {
  bool bezig =  Morse.busy 
  if (bezig == false ) {
   morse1.update();
   morse2.update();
}

 }

 void setup()
 {
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  
   timer.setInterval(5, repeatMe);

   delay(1000);
   morse1.send("1");
   morse2.send("2");
 }

 void loop() {
   timer.run();
   
   
 }

later today i will try this:

if ( morse1.busy == false ) { morse1.send("1 again"); }
if ( morse2.busy == false ) { morse2.send("2 again"); }

But dont know were to place this, i gues in the loop?
Or in the repeatMe()?

But dont know were to place this,

I see this line a lot from noobs. How to write the syntax of a line might be confusing, but the where to put it part shouldn't be. For a minute forget about code and just think about the logic. Those lines say, if the background process is finished sending then send this message. Code runs from top to bottom like a list of instructions. Just follow the flow and figure out where it goes. Start at the top of your code, pretend that you are the processor, maybe keep a pencil and paper to serve as your "memory" and walk through seeing what should happen.

Put that line in the list of instructions at the point in that process where you want the thing that line does to happen.

I agree.
But most times it ends up in trail and error.
Just trying them all.
Deep study is also an option but it is only this project for now and over a year i need to begin the same study again then...
And then time is getting a little problem.

Hihaaaa i am happy, thanks guys!

     if ( morse1.busy == false ) { morse1.send("1"); }
     if ( morse2.busy == false ) { morse2.send("2"); }

Does the job for me :wink:
Thanks!