Arduino UNO morse code

Hi! I’m fairly new to Arduino and I am struggling to find out what is wrong with my code.

I want a 4x4 Keypad to send a signal to my LED to create a visual morse code signal.

My code is in attachement and I think the problem is in linking the keypad to the morse code functions.

schets_examen_Maes__niet_af_.ino (2.84 KB)

i don't think you want the #include down to "Keypad customKeypad" in your setup().

move the 3 lines starting with setup() to the 2nd Serial.begin

thanks but that doesn’t seem to make a difference…

void loop(){
char customKey = customKeypad;

if (customKey){
Serial.println(customKey);

’customKeypad’ was not declared in this scope is the error I get but I don’t know
what is wrong about this part.

Please post your code.

int led =13;//the led pin
char input;// to save the input

void setup () {
pinMode (led,OUTPUT);//tell that the 13 pin is an output
Serial.begin(9600);//for the connect with the board

#include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 4;

char hexaKeys[ROWS][COLS] = {
{‘1’, ‘2’, ‘3’, ‘A’},
{‘4’, ‘5’, ‘6’, ‘B’},
{‘7’, ‘8’, ‘9’, ‘C’},
{’*’, ‘0’, ‘#’, ‘D’}

};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

Serial.begin(9600);
pinMode (led,OUTPUT);//tell that the 13 pin is an output
Serial.begin(9600);//for the connect with the board

};

void loop(){
char customKey = customKeypad;

if (customKey){
Serial.println(customKey);

if (Serial.available()) {
input = Serial.read();//read the input
if (input == ‘a’ || input == ‘A’) {lA();}//if the input is a or A go to function A
if (input == ‘b’ || input == ‘B’) {lB();}//same but with b letter
if (input == ‘c’ || input == ‘C’) {lC();}
if (input == ‘d’ || input == ‘D’) {lD();}
if (input == ‘1’) {n1();}// the numbers
if (input == ‘2’) {n2();}
if (input == ‘3’) {n3();}
if (input == ‘4’) {n4();}
if (input == ‘5’) {n5();}
if (input == ‘6’) {n6();}
if (input == ‘7’) {n7();}
if (input == ‘8’) {n8();}
if (input == ‘9’) {n9();}
if (input == ‘0’) {n0();}
if (input == ‘*’) {space();}//the space
Serial.println (input);//print the latter saved in the input var

}
}
//functions for the letters and the numbers
void A () {dot();dash();shortspace();}//letter A in morse code!
void B () {dash();dot();dot();dot();shortspace();}//same for B
void C () {dash();dot();dash();dot();shortspace();}
void D () {dash();dot();dot();shortspace();}
void 1 () {dot();dash();dash();dash();dash();shortspace();}//number 1 in morse code
void 2 () {dot();dot();dash();dash();dash();shortspace();}
void 3 () {dot();dot();dot();dash();dash();shortspace();}
void 4 () {dot();dot();dot();dot();dash();shortspace();}
void 5 () {dot();dot();dot();dot();dot();shortspace();}
void 6 () {dash();dot();dot();dot();dot();shortspace();}
void 7 () {dash();dash();dot();dot();dot();shortspace();}
void 8 () {dash();dash();dash();dot();dot();shortspace();}
void 9 () {dash();dash();dash();dash();dot();shortspace();}
void 0 () {dash();dash();dash();dash();dash();shortspace();}

void space () {delay (1200);}//space between words
void dot () {digitalWrite(led,HIGH); delay (300); digitalWrite(led,LOW); delay (300);}//the dot this code make the led on for 300 than off for 300
void dash () {digitalWrite(led,HIGH); delay (900); digitalWrite(led,LOW); delay (300);}//the dash this code make the led on for 900 than off for 300
void shortspace () {delay(600);}//space between letters

}
}

#include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 4;

char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}

};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};

should not be inside setup.

char customKey = customKeypad; That doesn’t look right.

Your code does Morse code for anything coming from the Serial port. If you want it to come from the keypad, use that variable instead

#include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 4;

char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}

};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

const int led = 13; //the led pin

void setup () {
  Serial.begin(9600);
  pinMode (led, OUTPUT); //tell that the 13 pin is an output
}


void loop() {
  //char customKey = customKeypad;
  char input = customKeypad.getKey();

  if (input) {
    Serial.println(input);

    if (input == 'A') MorseA();
    if (input == 'B') MorseB();
    if (input == 'C') MorseC();
    if (input == 'D') MorseD();
    if (input == '1') Morse1();
    if (input == '2') Morse2();
    if (input == '3') Morse3();
    if (input == '4') Morse4();
    if (input == '5') Morse5();
    if (input == '6') Morse6();
    if (input == '7') Morse7();
    if (input == '8') Morse8();
    if (input == '9') Morse9();
    if (input == '0') Morse0();
  }
}

//functions for the letters and the numbers
void MorseA () {
  dot();  //letter A in morse code!
  dash();
  shortspace();
}
void MorseB () {
  dash();  //same for B
  dot();
  dot();
  dot();
  shortspace();
}
void MorseC () {
  dash();
  dot();
  dash();
  dot();
  shortspace();
}
void MorseD () {
  dash();
  dot();
  dot();
  shortspace();
}
void Morse1 () {
  dot();  //number 1 in morse code
  dash();
  dash();
  dash();
  dash();
  shortspace();
}
void Morse2 () {
  dot();
  dot();
  dash();
  dash();
  dash();
  shortspace();
}
void Morse3 () {
  dot();
  dot();
  dot();
  dash();
  dash();
  shortspace();
}
void Morse4 () {
  dot();
  dot();
  dot();
  dot();
  dash();
  shortspace();
}
void Morse5 () {
  dot();
  dot();
  dot();
  dot();
  dot();
  shortspace();
}
void Morse6 () {
  dash();
  dot();
  dot();
  dot();
  dot();
  shortspace();
}
void Morse7 () {
  dash();
  dash();
  dot();
  dot();
  dot();
  shortspace();
}
void Morse8 () {
  dash();
  dash();
  dash();
  dot();
  dot();
  shortspace();
}
void Morse9 () {
  dash();
  dash();
  dash();
  dash();
  dot();
  shortspace();
}
void Morse0 () {
  dash();
  dash();
  dash();
  dash();
  dash();
  shortspace();
}

void space () {
  delay (1200); //space between words
}

void dot () {
  digitalWrite(led, HIGH);  //the dot this code make the led on for 300 than off for 300
  delay (300);
  digitalWrite(led, LOW);
  delay (300);
}

void dash () {
  digitalWrite(led, HIGH);  //the dash this code make the led on for 900 than off for 300
  delay (900);
  digitalWrite(led, LOW);
  delay (300);
}

void shortspace () {
  delay(600); //space between letters
}

Thank you very much!