first code attempt

I keep getting "a function-definition is not allowed here before '{' token"
this come after I have re-arranged my code several times, my code is supposed to make an LED blink "hello welcome to mechatronics" in morse code.

int led=13;// the led pin
char input;// to save the input
void setup () {

pinMode(led, OUTPUT);
Serial.begin(9600);

}

// the loop function runs over and over again forever
void loop() {
if (Serial.available()) {
input = Serial.read();//read the input
void H() {d();d();d();d();p();d();p();d();l();d();d();p();d();l();d();d();p();l();l();l();pause();d();l();l();p();d();p();d();l();d();d();p();l();d();l();d();p();l();l();l();p();l();l();p();d();pause();l();p();l();l();l();pause();l();l();p();d();p();l();d();l();d();p();d();d();d();d();p();d();l();p();l();p();d();l();d();p();l();l();l();p();l();d();p();d();d();p();l();d();l();d();p();d();d();d();

}
void d () {digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(200); // wait
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(200);} // wait
void l () {digitalWrite(led, HIGH);
delay(600);
digitalWrite(led, LOW);
delay(200);}
void p () {delay(600);} //space bewteen letter
void pause() {delay(1400);} //space between word

if (input == 'h') {H();} //function to greet user

First of all, please use code tags.

Secondly, no wonder, that’s not the way of making an array of functions. Why are you trying to do it that way in the first place?

This is a more sensible way.

byte morse[] = {1,1,1,0,2,2,2,0,1,1,1};
byte length = 11;

for (byte i = 1; i++; i < length) {
  switch (morse[i]) {
    case 0:
      pause();
      break;

    case 1:
      dit();
      break;

    case 2:
      doot();
      break;
  }
}

without reading the code too closely - that error message usually means you have an imbalance of curly brackets.

in the IDE, put your cursor to each curly bracket - and there will be a matching highlight to show where the other of the pair is.

just keep doing that through your code to make sure you have the curly brackets in the right place.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

You cannot use “pause” as a variable of function name, it is reserved, that is why it is a different colour than your other functions

Tom… :slight_smile:

You have to define functions outside of other functions. You try to define H(), d(), l(), p() and pause() inside of loop(), which is a function.

define:

void myFunction()
{
Serial.write( 'x' );
}

use:

void loop()
{
myFunction(); // prints letter x
delay( 1000 ); // 16 million cpu cycles just wasted
}

You should find the links on this Arduino site page very helpful:

Hi,
You code in its present configuration was so close.
Try this, I have added so debug Serial.prints so you can see what is happening;

int led = 13; // the led pin
char input;// to save the input
void setup () {

  pinMode(led, OUTPUT);
  Serial.begin(9600);

}

// the loop function runs over and over again forever
void loop() {
  if (Serial.available()) {
    input = Serial.read();//read the input

    d(); d(); d(); d(); p(); d(); p(); d(); l(); d(); d(); p(); d(); l(); d(); d(); p(); l(); l(); l(); p(); d(); l(); l(); p(); d(); p(); d(); l(); d(); d(); p(); l(); d(); l(); d(); p(); l(); l(); l(); p(); l(); l(); p(); d(); p(); l(); p(); l(); l(); l(); p(); l(); l(); p(); d(); p(); l(); d(); l(); d(); p(); d(); d(); d(); d(); p(); d(); l(); p(); l(); p(); d(); l(); d(); p(); l(); l(); l(); p(); l(); d(); p(); d(); d(); p(); l(); d(); l(); d(); p(); d(); d(); d();

  }
}
//--------
void d () {
  Serial.print("dit  ");
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(200);                       // wait
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(200);
}                                 // wait
void l () {
  Serial.print("dah  ");
  digitalWrite(led, HIGH);
  delay(600);
  digitalWrite(led, LOW);
  delay(200);
}
//-------------------------
void p () {
  delay(600); //space bewteen letter
  Serial.println(" ");
  Serial.println("pause");
}
//---------------------------

Just send a single character in the monitor and it should go.
It works here.
Tom… :slight_smile: