Beginner function problem

Hey there,
i just started playing around with an arduino uno. I gathered some programming experience in school und university and i felt quite good programming the first "real" project.
I tried to translate my name into morse-code and a flashing led, but something went wrong.

void blink_dot(){
digitalWrite(led, HIGH);
delay(500); // Led turns on 500ms
digitalWrite(led, LOW);
delay(500);
}

These functions do work, but i tried to cut down on code and did something like this:

void blink_strichdot(){
blink_strich;
blink_dot;
}

I wanted a function which starts blink_strich and blink_dot (blink strich is the same as blink_dot with different timings).

From these new functions i created my "letter functions"

void d_Morse(){
blink_strichstrich;
blink_dot;
}

After compiling the whole code there were no errors, but the led did not do anything..
Maybe you can help me!

int led = 13 ;

void setup() {
  pinMode(led, OUTPUT);       // pin13 auf dem Arduino wird als Output festgelegt
}

void blink_dot(){             // Funktion für Punkt 
  digitalWrite(led, HIGH);    
  delay(500);                 // Led leuchtet 500ms
  digitalWrite(led, LOW);
  delay(500);                 // Nach jedem Zeichen folgt eine 1Punkt Pause, also 500ms
}
void blink_strich(){          // Funktion für Strich
  digitalWrite(led, HIGH);
  delay(1500);                // Led leuchtet 3Punkt lang
  digitalWrite(led, LOW);
  delay(500);                 // Nach jedem Zeichen folgt eine 1Punkt Pause, also 500ms
}
void break_long(){            //Funktion für Pause zwischen Wörtern ist 7Punkte,
  delay(3000);                // da in den Leuchten eine 1Punkt Pause eingebaut ist   
}                             // 7Punkt-1Punkt=3500-500=3000ms


void blink_dotdot(){          // Funktion für PunktPunkt leuchten
  blink_dot;
  blink_dot;
}

void blink_strichdot(){       // Funktion für StrichPunkt leuchten
  blink_strich;
  blink_dot;
}

void blink_strichstrich(){   // Funktion für StrichStrich leuchten
  blink_strich;
  blink_strich;
}

void d_Morse(){
  blink_strichstrich;
  blink_dot;  
}

void o_Morse(){
  blink_strichstrich;
  blink_strich;  
}

void m_Morse(){
  blink_strichstrich; 
}

void i_Morse(){
  blink_strichstrich;  
}

void n_Morse(){
  blink_strichdot;  
}

void c_morse(){
  blink_strichdot;
  blink_strichdot;
}

void loop()
{
  blink_dot();
  d_Morse();
  o_Morse();
  m_Morse();
  blink_dotdot();
  n_Morse();
  blink_dotdot();
  c_morse();
  delay(1500);
}
void d_Morse(){
  blink_strichstrich;  // evaluating a pointer to the function code and then ignore it
  blink_dot;   // evaluating a pointer to the function code and ignoring it

  // perhaps you meant to call the functions?
  blink_strichstrich () ;
  blink_dot () ;
}

First, try to write your code so the words per minute can be changed easily. If you want to change the code speed, change the DOTDELAY value and everything else gets changed automatically since all timings are based on that value...simply change and recompile.

Second, writing a function for each letter is the hard way to do it. For a much easier way to do it, look at post #6:

http://forum.arduino.cc/index.php?topic=284639.0;nowap

#define DOTDELAY  500             // Standard spacings
#define DAHDELAY  (DOTDELAY * 3)
#define WORDDELAY (DOTDELAY * 7)

int led = 13 ;

void setup() {
  pinMode(led, OUTPUT);       // pin13 auf dem Arduino wird als Output festgelegt
}

void blink_dot(){             // Funktion für Punkt 
  digitalWrite(led, HIGH);    
  delay(DOTDELAY);                 // Led leuchtet 500ms
  digitalWrite(led, LOW);
  delay(DOTDELAY);                 // Nach jedem Zeichen folgt eine 1Punkt Pause, also 500ms
}
void blink_strich(){          // Funktion für Strich
  digitalWrite(led, HIGH);
  delay(DAHDELAY);                // Led leuchtet 3Punkt lang
  digitalWrite(led, LOW);
  delay(DOTDELAY);                 // Nach jedem Zeichen folgt eine 1Punkt Pause, also 500ms
}
void break_long(){            //Funktion für Pause zwischen Wörtern ist 7Punkte,
  delay(3000);                // da in den Leuchten eine 1Punkt Pause eingebaut ist   
}                             // 7Punkt-1Punkt=3500-500=3000ms


void blink_dotdot(){          // Funktion für PunktPunkt leuchten
  blink_dot;
  blink_dot;
}

void blink_strichdot(){       // Funktion für StrichPunkt leuchten
  blink_strich;
  blink_dot;
}

void blink_strichstrich(){   // Funktion für StrichStrich leuchten
  blink_strich;
  blink_strich;
}

void d_Morse(){
  blink_strichstrich;
  blink_dot;  
}

void o_Morse(){
  blink_strichstrich;
  blink_strich;  
}

void m_Morse(){
  blink_strichstrich; 
}

void i_Morse(){
  blink_strichstrich;  
}

void n_Morse(){
  blink_strichdot;  
}

void c_morse(){
  blink_strichdot;
  blink_strichdot;
}

void loop()
{
  blink_dot();
  d_Morse();
  o_Morse();
  m_Morse();
  blink_dotdot();
  n_Morse();
  blink_dotdot();
  c_morse();
  delay(1500);
}

Thanks at MarkT! I thought i oversaw something stupid.. now it works :slight_smile: Thanks!

@econjack Thanks aswell to you for your answer, but it's a task for university and it only wants us to spell our own name :slight_smile:

But i try to use ur input aswell to improve my code further :slight_smile:

blutt:
Thanks at MarkT! I thought i oversaw something stupid.. now it works :slight_smile: Thanks!

@econjack Thanks aswell to you for your answer, but it's a task for university and it only wants us to spell our own name :slight_smile:

But i try to use ur input aswell to improve my code further :slight_smile:

You did not do anything stupid, the Arduino IDE concept of NOT requiring function prototypes for sake of "not confusing beginners " strike again!

The hidden function prototype was declared wrong - it does no matter how wrong , so the compiler had no means to check your incorrect syntax - missing ( ) after the function name und before ;
If you declare function by yourself - void MySignature(void); the compiler will flag your incorrect usage / syntax as error.

This is one of the good reasons function prototypes concept was adopted and one should NOT relay on Arduino IDE to write the functions prototypes for you.

Jim .... ..

julyjim:
You did not do anything stupid, the Arduino IDE concept of NOT requiring function prototypes for sake of "not confusing beginners " strike again!

The hidden function prototype was declared wrong - it does no matter how wrong , so the compiler had no means to check your incorrect syntax - missing ( ) after the function name und before ;
If you declare function by yourself - void MySignature(void); the compiler will flag your incorrect usage / syntax as error.

Hmm, I tried the below in both the Arduino IDE and VS2012/C++. Both seem to be very happy when compiling.

void doSomething()
{

}

void setup()
{
  doSomething;
}

void loop()
{

}

sterretje:
Hmm, I tried the below in both the Arduino IDE and VS2012/C++. Both seem to be very happy when compiling.

void doSomething()

{

}

void setup()
{
  doSomething;
}

void loop()
{

}

There is nothing syntactically wrong with that code, so it will not give a compile error. It simply won't do what the OP wanted - the function is NOT called. a bare function name resolves to a pointer to the function, but nothing is done with that pointer, so that line of code is simply optimized away.

There is also nothing syntactically wrong with this code, it just doesn't do anything useful:

void setup()
{
  3;
}

void loop()
{
 236;
}

Regards,
Ray L.

I know that :wink: But julyjim blames the IDE for that which is not the case.

julyjim:
You did not do anything stupid, the Arduino IDE concept of NOT requiring function prototypes for sake of "not confusing beginners " strike again!

The hidden function prototype was declared wrong - it does no matter how wrong , so the compiler had no means to check your incorrect syntax - missing ( ) after the function name und before ;
If you declare function by yourself - void MySignature(void); the compiler will flag your incorrect usage / syntax as error.

This is one of the good reasons function prototypes concept was adopted and one should NOT relay on Arduino IDE to write the functions prototypes for you.

Jim .... ..

How does that quote go?
Something about speaking out, and removing any doubt? :smiley: