conbination of two codes ! (4x4 keypad to 16x2 lcd texter), morse EnDecoder !

i have found those two beautiful projects.

both guys did them should take a lot of credits .

first project.

code is way to big to fit in just one post, i'll send it in 3 - 4 post right up.

second project

http://raronoff.wordpress.com/2010/12/16/morse-endecoder/
code can be found and downloaded with the libraries needed for this EnDecoder here
https://code.google.com/p/morse-endecoder/downloads/list

the first one takes everything from the lcd and post them to Serial Window by the press of "enter" Button.

seccond one reads everything from Serial and decodes it to morse code so it can be outputed through pin13 to an 8Ohm speaker.

i have everything on one Arduino Uno.

problem is i can't get them to work together.

in the next post i will have the parts of the first project ( the texter).

part one

//Clayton Ford 
//With assistance from Mark Tortorich
//Texting old-school style with a Hitachi-compatible 16x2 LCD and a 4x4 keypad
//with added text storage and serial return of typed text.
//This code and hardware setup, without much additional effort, could actually 
//send text messages upon the addition of a cellular shield and relatively 
//minor changes to this code.

#include <LiquidCrystal.h> //include the lcd library
const byte row1=3; //keypad row pins, shared with the lcd data lines
const byte row2=4;
const byte row3=5;
const byte row4=6;
const byte col1=7; //keypad column lines
const byte col2=8;
const byte col3=9;
const byte col4=10;
LiquidCrystal lcd(12, 11, row4, row3, row2, row1); //lcd object
byte numpressed; //latest number pressed on the keypad
byte timespressed; //times the number has been pressed
byte cursorx=0; //cursor x position
byte cursory=0; //cursor y position
char letter; //stores letter that needs to be printed to the lcd
const int wait=1000; //time to wait for additional presses to same number
const int preventholddelay=150; //time to wait to prevent cycling through things too quickly
unsigned long basetime; //base time for while loop
unsigned long elapsed=0; //elapsed time in while loop
byte lastnumpressed; //the initial number pressed on the keypad
bool disablespacedelay=false; //disables the delay in the space function in the case that a different number is pressed while in while loop
const byte maxtimespressed[16]={
  1,3,4,4,4,4,4,4,4,4,1,7,1,1,1,1}; //stores maximum number of times any given key can be pressed before looping back to its first letter (used by incrementtimespressed function)
char typedtext[140]; //stores typed text for printout to the serial console
int positionintypedtext=0; //position in typedtext character array
int charremaining; //remaining characters in message
bool promptkeypress=false; //used for waiting for, and keypress detection, at the end-of composition prompt

void setup(){
  Serial.begin(115200); //start serial communication so that we can print the typed text to the serial console
  lcd.begin(16,2); //initialize the lcd
  lcd.setCursor(cursorx,cursory); //set the lcd cursor
  lcd.noCursor(); //turn off the cursor
  pinMode(row1,OUTPUT); //set the rows as outputs
  pinMode(row2,OUTPUT);
  pinMode(row3,OUTPUT);
  pinMode(row4,OUTPUT);
  pinMode(col1,INPUT); //set the  columns as inputs
  pinMode(col2,INPUT);
  pinMode(col3,INPUT);
  pinMode(col4,INPUT);
  delay(wait);
  lcd.cursor(); //turn the cursor on again after a delay equivalent to wait
  rowshigh(); //sets all rows high
}

void loop(){
  numpressed=16; //reset "numpressed" (16 doesn't refer to any button on the pad)
  if (findpress()){ //look for presses, if one has occurred, identify it and continue
    timespressed=0; //reset "timespressed"
    if (numpressed==0){ //if zero on the pad was pressed,
      dozero(); //print zero
      letter='0'; //manually seed a zero as the character for the text storage
      textstorage(1); //regular character storage
    }
    if (numpressed==10){ //if shift on the pad was pressed,
      textstorage(2); //perform a space in storage
      dospace(); //do a space
    }
    if (numpressed==14){ //if the arrows on the pad were pressed,
      textstorage(3); //perform a backspace in storage
      dobackspace(); //do a backspace
    }
    if (numpressed==15){ //if enter on the pad was pressed,
      outputserial(); //output message and display remaining characters to serial console
    }
    if ((numpressed<10&&numpressed>0)||numpressed==11){ //if 1,2,3,4,5,6,7,8,9, or 11 was pressed (any one of the keys with multiple characters assigned),
      lastnumpressed=numpressed; //record which number was pressed,
      basetime=millis(); //and take a base time for the while loop
      while (elapsed<wait){ //while below the time to wait,
        if(findpress()){ //look for presses, if one has occurred, identify it and continue
          if (numpressed==lastnumpressed){ //if it was the same as before,
            incrementtimespressed(); //increment "timespressed"
            basetime=basetime+(wait-(wait-elapsed)); //roll up the base time, to allow another wait period until next press of the same button
            definepress(); //use "numpressed" and "timespressed" to define "letter"
            lcd.print(letter); //print the letter that was defined
            lcd.setCursor(cursorx,cursory); //maintain cursor position
            rowshigh(); //return all rows high
            delay(preventholddelay); //delay a little to prevent continuous cycling through "timespressed" during a single press
          }
          else{ //if the number that was pressed was different than before,
            disablespacedelay=true; //disable the delay in the space function to allow the press to be detected a second time, at the beginning of void loop
            break; //break out of the while loop
          }
        }
        elapsed=millis()-basetime; //refresh the elapsed time for the while loop
      }
      elapsed=0; //reset the elapsed time for the while loop
      textstorage(1); //store character
      dospace(); //do a space
    }
  }
  if (positionintypedtext==139){ //if the end of the stored text has been reached,
    promptkeypress=false; //reset keypress detection
    cursorx=0; //set cursor to the beginning of first row
    cursory=0;
    lcd.setCursor(cursorx,cursory);
    lcd.print("Msg end. <>=back"); //print this out to the lcd
    cursorx=0; //set cursor to the beginning of second row
    cursory=1;
    lcd.setCursor(cursorx,cursory);
    lcd.print("enter=serial out"); //print this out to the lcd
    rowshigh(); //sets all rows high
    numpressed=16; //reset "numpressed" (16 doesn't refer to any button on the pad)
    while(!promptkeypress){ //while no relevant keypresses have occurred, 
      if (findpress()){ //look for presses, if one has occurred, identify it and continue
        timespressed=0; //reset "timespressed"
        if (numpressed==14){ //if the arrows on the pad were pressed,
          promptkeypress=true; //take note so that the while loop can be broken
          textstorage(3); //perform a backspace in storage
          for (int i=0;i<16;i++){ //print out to the first line on the lcd from the stored text
            cursorx=i;
            cursory=0;
            lcd.setCursor(cursorx,cursory);
            lcd.print(typedtext[108+i]);
          }
          for (int j=0;j<16;j++){ //print out to the second line on the lcd from the stored text
            cursorx=j;
            cursory=1;
            lcd.setCursor(cursorx,cursory);
            lcd.print(typedtext[123+j]);
          }
          cursorx=15; //set cursor to the beginning of second row
          cursory=1;
          lcd.setCursor(cursorx,cursory);
          rowshigh(); //sets all rows high
        }
        if (numpressed==15){ //if enter on the pad was pressed,
          promptkeypress=true; //take note so that the while loop can be broken
          Serial.print("Final message: "); //print this to the serial console
          Serial.println(typedtext); //print out all the text typed so far to the serial console
          Serial.println(); //print a blank line
          for (int i=0;i<140;i++){ //write all positions in the stored text to be blank
            typedtext[i]=' ';
          }
          positionintypedtext=0; //reset the position in the stored text to the beginning
          doclear();
          rowshigh(); //sets all rows high
        }
      }
    }
    delay(preventholddelay); //delay a little to prevent continuous cycling
  }
}

part two

void rowshigh(){ //sets all rows high
  digitalWrite(row1,HIGH); //write all the rows high
  digitalWrite(row2,HIGH); 
  digitalWrite(row3,HIGH);
  digitalWrite(row4,HIGH);
}

bool findpress(){ //finds a press to define "numpressed", if any press occurs, returns true
  bool pressfound=false; //variable for any press detection, is returned by this function

  digitalWrite(row1,LOW); //write all rows low
  digitalWrite(row2,LOW);
  digitalWrite(row3,LOW);
  digitalWrite(row4,LOW);

  digitalWrite(row1,HIGH); //write first row high
  if (digitalRead(col1)==HIGH){ //if the first column is now high, "1" has been pressed
    numpressed = 1;
    pressfound=true;
  }
  if (digitalRead(col2)==HIGH){ //if the second column is now high, "2" has been pressed
    numpressed = 2;
    pressfound=true;
  }
  if (digitalRead(col3)==HIGH){ //if the third column is now high, "3" has been pressed
    numpressed = 3;
    pressfound=true;
  }
  if (digitalRead(col4)==HIGH){ //if the fourth column is now high, "reset" has been pressed
    numpressed = 12;
    pressfound=true;
  }
  digitalWrite(row1,LOW); //return first row low

  digitalWrite(row2,HIGH); //write second row high
  if (digitalRead(col1)==HIGH){ //if the first column is now high, "4" has been pressed
    numpressed = 4;
    pressfound=true;
  }
  if (digitalRead(col2)==HIGH){ //if the second column is now high, "5" has been pressed
    numpressed = 5;
    pressfound=true;
  }
  if (digitalRead(col3)==HIGH){ //if the third column is now high, "6" has been pressed
    numpressed = 6;
    pressfound=true;
  }
  if (digitalRead(col4)==HIGH){ //if the fourth column is now high, "dial" has been pressed
    numpressed = 13;
    pressfound=true;
  }
  digitalWrite(row2,LOW); //return second row low

  digitalWrite(row3,HIGH); //write third row high
  if (digitalRead(col1)==HIGH){ //if the first column is now high, "7" has been pressed
    numpressed = 7;
    pressfound=true;
  }
  if (digitalRead(col2)==HIGH){ //if the second column is now high, "8" has been pressed
    numpressed = 8;
    pressfound=true;
  }
  if (digitalRead(col3)==HIGH){ //if the third column is now high, "9" has been pressed
    numpressed = 9;
    pressfound=true;
  }
  if (digitalRead(col4)==HIGH){ //if the fourth column is now high, the arrows have been pressed
    numpressed = 14;
    pressfound=true;
  }
  digitalWrite(row3,LOW); //return third row low

  digitalWrite(row4,HIGH); //write fourth row high
  if (digitalRead(col1)==HIGH){ //if the first column is now high, "shift" has been pressed
    numpressed = 10;
    pressfound=true;
  }
  if (digitalRead(col2)==HIGH){ //if the second column is now high, "0" has been pressed
    numpressed = 0;
    pressfound=true;
  }
  if (digitalRead(col3)==HIGH){ //if the third column is now high, "." has been pressed
    numpressed = 11;
    pressfound=true;
  }
  if (digitalRead(col4)==HIGH){ //if the fourth column is now high, "enter" has been pressed
    numpressed = 15;
    pressfound=true;
  }
  digitalWrite(row4,LOW); //return fourth row low

  rowshigh(); //write all rows high

    return pressfound; //function returns true if any press found, otherwise returns false
}

part 3

void definepress(){ //uses "lastnumpressed" and "timespressed" to define "letter"
  if (lastnumpressed==1){
    if (timespressed==1){
      letter='Q';
    }
    if (timespressed==2){
      letter='Z';
    }
    if (timespressed==3){
      letter='1';
    }
  }
  if (lastnumpressed==2){
    if (timespressed==1){
      letter='A';
    }
    if (timespressed==2){
      letter='B';
    }
    if (timespressed==3){
      letter='C';
    }
    if (timespressed==4){
      letter='2';
    }
  }
  if (lastnumpressed==3){
    if (timespressed==1){
      letter='D';
    }
    if (timespressed==2){
      letter='E';
    }
    if (timespressed==3){
      letter='F';
    }
    if (timespressed==4){
      letter='3';
    }
  }
  if (lastnumpressed==4){
    if (timespressed==1){
      letter='G';
    }
    if (timespressed==2){
      letter='H';
    }
    if (timespressed==3){
      letter='I';
    }
    if (timespressed==4){
      letter='4';
    }
  }
  if (lastnumpressed==5){
    if (timespressed==1){
      letter='J';
    }
    if (timespressed==2){
      letter='K';
    }
    if (timespressed==3){
      letter='L';
    }
    if (timespressed==4){
      letter='5';
    }
  }
  if (lastnumpressed==6){
    if (timespressed==1){
      letter='M';
    }
    if (timespressed==2){
      letter='N';
    }
    if (timespressed==3){
      letter='O';
    }
    if (timespressed==4){
      letter='6';
    }
  }
  if (lastnumpressed==7){
    if (timespressed==1){
      letter='P';
    }
    if (timespressed==2){
      letter='R';
    }
    if (timespressed==3){
      letter='S';
    }
    if (timespressed==4){
      letter='7';
    }
  }
  if (lastnumpressed==8){
    if (timespressed==1){
      letter='T';
    }
    if (timespressed==2){
      letter='U';
    }
    if (timespressed==3){
      letter='V';
    }
    if (timespressed==4){
      letter='8';
    }
  }
  if (lastnumpressed==9){
    if (timespressed==1){
      letter='W';
    }
    if (timespressed==2){
      letter='X';
    }
    if (timespressed==3){
      letter='Y';
    }
    if (timespressed==4){
      letter='9';
    }
  }
  if (lastnumpressed==11){
    if (timespressed==1){
      letter='.';
    }
    if (timespressed==2){
      letter='?';
    }
    if (timespressed==3){
      letter='!';
    }
    if (timespressed==4){
      letter=',';
    }
    if (timespressed==5){
      letter='\'';
    }
    if (timespressed==6){
      letter='"';
    }
    if (timespressed==7){
      letter='-';
    }
  }
}

part 4

void incrementtimespressed(){ //increment "timespressed" until at max value stored in maxtimespressed for that lastnumpressed, then roll over to 1
  if (timespressed==maxtimespressed[lastnumpressed]){ //if at the maximum,
    timespressed=1; //roll over timespressed to one
  }
  else{ //otherwise,
    timespressed++; //increment timespressed
  }
}

void dozero(){ //prints zero
  lcd.print('0'); //print 0
  lcd.setCursor(cursorx,cursory); //maintain cursor position
  dospace(); //space
}

void dospace(){ //moves cursor forward once, wraps to next line if necessary, clears and returns to top of display if at bottom
  if (cursory==1){ //if on the bottom row,
    if (cursorx==15){ //if at the end of the row,
      cursorx=0; //define new cursor position as the upper-left corner
      cursory=0;
      lcd.clear(); //clear the lcd
    }
    else{ //otherwise,
      cursorx++; //increment the cursor to the right
    }
  }
  else{ //if on the top row,
    if (cursorx==15){ //if at the end of the row,
      cursorx=0; //define new cursor position as the bottom-left corner
      cursory=1;
    }
    else{ //otherwise,
      cursorx++; //increment the cursor to the right
    }
  }
  lcd.setCursor(cursorx,cursory); //set cursor to defined location
  rowshigh(); //sets all rows high
  if (disablespacedelay){ //if the delay has been disabled,
    disablespacedelay=false; //reset its being disabled
  }
  else{ //otherwise,
    delay(preventholddelay); //delay a bit
  }
}

void doclear(){ //clears and returns to top-left of display
  cursorx=0;
  cursory=0;
  lcd.clear();
  lcd.setCursor(cursorx,cursory);
  rowshigh(); //sets all rows high
  delay(preventholddelay);
}

void dobackspace(){ //does a backspace, essentially the opposite of dospace
  if (cursory==1){
    if (cursorx==0){
      cursorx=15;
      cursory=0;
    }
    else{
      cursorx--;
    }
  }
  else{
    if (cursorx==0){
      cursorx=0;
      cursory=0;
    }
    else{
      cursorx--;
    }
  }
  lcd.setCursor(cursorx,cursory);
  lcd.print(" ");
  lcd.setCursor(cursorx,cursory);
  rowshigh(); //sets all rows high
  delay(preventholddelay);
}

void textstorage(byte mode){ //contains functions for text storage
  if (mode==1){ //regular character storage
    typedtext[positionintypedtext]=letter; //store letter that was printed to LCD in typedtext
    positionintypedtext++; //increment position in typedtext
  }
  if (mode==2){ //do a space in stored text
    typedtext[positionintypedtext]=' '; //set current position in typedtext to a space
    positionintypedtext++; //increment position in typedtext
  }
  if (mode==3){ //does a backspace in the stored text
    positionintypedtext--; //decrement position in typedtext
    typedtext[positionintypedtext]=' '; //set current position in typedtext to a space
  }
}

void outputserial(){ //output message and display remaining characters to serial console
  Serial.print("Message: ");
  Serial.println(typedtext); //print out all the text typed so far to the serial console
  charremaining=(139-(positionintypedtext)); //calculate remaining characters
  Serial.print(charremaining); //display remaining characters
  if (charremaining==1){ //making sure that the plural is only used correctly
    Serial.println(" character remaining");
  }
  else{
    Serial.println(" characters remaining");
  }
  Serial.println(); //print a blank line
  delay(preventholddelay); //delay a little to prevent continuous cycling
}

the EnDecoder code

/*
                MORSE ENDECODER DEMO

  Demonstrates using Morse encoder and decoder classes for the Arduino.

  Local Morse code feedback to both serial and Morse output (unless sending 
    at the same time as receiving or keying in morse), for morse training demo.
  Formatted serial port output - Serial monitor looks a bit nicer.


  This example decodes Morse code signals with a speed of 13 WPM present on
    digital input 7 (active low, and also using the internal pullup resistor).

  It also encodes Morse code sent via the serial interface to the Arduino,
    on digital output pin 13. Speed is 13 WPM also (easily changed in code).
  
  It can also decode audible signals, if using the constant MORSE_AUDIO
    instead of MORSE_KEYER, but then it is important to note that the
    input pin nr. will be for ANALOG inputs (0-5 on Atmega 168 - 328),
    and not the digital inputs.



  Copyright (C) 2010, 2012 raron
  
  GNU GPLv3 license:
  
  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/>.
   
  
  Contact: raronzen@gmail.com  (not checked too often..)
  Details: http://raronoff.wordpress.com/2010/12/16/morse-endecoder/
*/

#include <avr/pgmspace.h>
#include <MorseEnDecoder.h>

// Pin mappings
const byte morseInPin = 2;      
const byte morseOutPin = 13;
// Instantiate Morse objects
morseDecoder morseInput(morseInPin, MORSE_KEYER, MORSE_ACTIVE_LOW);
morseEncoder morseOutput(morseOutPin);

// Variables dealing with formatting the output somewhat
// by inserting CR's (carriage returns)
long lastTransmissionTime;
long currentTime;
boolean transmissionEnded = true; // Flag to mark old transmission is finished

// Minimum transmission pause time to insert carriage returns (CR)
// Adjust depending on Morse speed. IE 13 wpm = 646 ms between words (no CR).
const long transmissionPaused   = 1000; // Suitable for 13 wpm?


void setup()
{
  Serial.begin(9600);
  Serial.println("Morse EnDecoder demo");
  
  // Setting Morse speed in wpm - words per minute
  // If not set, 13 wpm is default anyway
  morseInput.setspeed(13);
  morseOutput.setspeed(13);
  
  lastTransmissionTime = (long)millis();
}



void loop()
{
  currentTime = (long)millis();
  
  // Needs to call these once per loop
  morseInput.decode();
  morseOutput.encode();

  // SEND MORSE (OUTPUT)
  // Encode and send text received from the serial port (serial monitor)
  if (Serial.available() && morseOutput.available())
  {
    // Get character from serial and send as Morse code
    char sendMorse = Serial.read();
    morseOutput.write(sendMorse);
    // Not strictly needed, but used to get morseSignalString before it is destroyed
    // (E.g. for morse training purposes)
    morseOutput.encode();

    // Also write sent character + Morse code to serial port/monitor
    Serial.write(' ');
    Serial.write(sendMorse);
    Serial.write(morseOutput.morseSignalString);
  }


  // RECEIVE MORSE (INPUT)
  // If a character is decoded from the input, write it to serial port
  if (morseInput.available())
  {
    // Get decoded Morse code character and write it to serial port/monitor
    char receivedMorse = morseInput.read();
    Serial.print(receivedMorse);
    
    // A little error checking    
    if (receivedMorse == '#') Serial.println("< ERROR:too many morse signals! >");
  }


  // Local Morse code feedback from input if not sending Morse simultaneously
  if (morseOutput.available()) digitalWrite(morseOutPin, morseInput.morseSignalState);


  // Check if ongoing transmission (not yet transmission pause)
  if (!morseOutput.available() || morseInput.morseSignalState == true)
  {
    // reset last transmission timer and flag
    lastTransmissionTime = currentTime;
    transmissionEnded = false;
  }

  // Format output with carriage returns after a transmission pause
  if ((currentTime - lastTransmissionTime) > transmissionPaused)
  {
    if (transmissionEnded == false)
    {
      // Separate the transmissions somewhat in the serial monitor with CR's
      for (int cr=0; cr<2; cr++) Serial.println("");  // some carriage returns..
      
      // Finally set the flag to prevent continous carriage returns
      transmissionEnded = true;
    }
  }
}

i know that it has to do something with two variables
1 ) typedtext // a string of every chars that were typed on the lcd.
2) sendMorse // a char that the encoder converts to morse code

so far came up with this :

this is the last function in the texter code :

void outputserial(){ //output message and display remaining characters to serial console
  Serial.print("Message: ");
  Serial.println(typedtext); //print out all the text typed so far to the serial console
  charremaining=(139-(positionintypedtext)); //calculate remaining characters
  Serial.print(charremaining); //display remaining characters
  if (charremaining==1){ //making sure that the plural is only used correctly
    Serial.println(" character remaining");
  }
  else{
    Serial.println(" characters remaining");
  }
  Serial.println(); //print a blank line
  delay(preventholddelay); //delay a little to prevent continuous cycling
}

and changed it to this.

void outputserial(){ //output message and display remaining characters to serial console
    if (morseOutput.available())
  {
  // Get character from serial and send as Morse code
     for (int i=0;i<14;i++){ //write all positions in the stored text to be blank   
       char sendMorse = typedtext[i];
       Serial.println(sendMorse);
       morseOutput.write(sendMorse);
       morseOutput.encode();  
        }
  }
  // RECEIVE MORSE (INPUT)
  // If a character is decoded from the input, write it to serial port
  if (morseInput.available())
  {
    // Get decoded Morse code character and write it to serial port/monitor
    char receivedMorse = morseInput.read();
    Serial.print(receivedMorse);
    
    // A little error checking    
    if (receivedMorse == '#') Serial.println("< ERROR:too many morse signals! >");
  }


  // Local Morse code feedback from input if not sending Morse simultaneously
  if (morseOutput.available()) digitalWrite(morseOutPin, morseInput.morseSignalState);


  // Check if ongoing transmission (not yet transmission pause)
  if (!morseOutput.available() || morseInput.morseSignalState == true)
  {
    // reset last transmission timer and flag
    lastTransmissionTime = currentTime;
    transmissionEnded = false;
  }

  // Format output with carriage returns after a transmission pause
  if ((currentTime - lastTransmissionTime) > transmissionPaused)
  {
    if (transmissionEnded == false)
    {
      // Separate the transmissions somewhat in the serial monitor with CR's
      for (int cr=0; cr<2; cr++) Serial.println("");  // some carriage returns..
      
      // Finally set the flag to prevent continous carriage returns
      transmissionEnded = true;
    }
  }
    // Not strictly needed, but used to get morseSignalString before it is destroyed
    // (E.g. for morse training purposes)
    morseOutput.encode();
delay(preventholddelay);
}

and actualy it works up to the point of when ever i Serial.println(sendMorse) inside the for loop i see that it has all the chars from the lcd. but i hear nothing on the speaker.

of course all sort of declarations from the EnDecoder where made to the texter code and libraries included.

a litle bit lost here,

any one has any idea on this ?

thank you all for your time reading this.

Just to clarify, are you trying to combine the two projects so you type something on the matrix keypad and convert it to morse code to be played via speaker? And you can't combine the two pieces of code?

As a side note, when I was scanning through the code, it's a bit better to use a switch ( ) statement instead of using a lot of "if then" statements.

The other thing is using delay(). I know with the keypad library, delay caused the keypad reads to be very slow. What I did to keep the LCD from constantly refreshing and readable was only refresh it after a certain period of time has elapsed by using millis().

Yes psychephylax this is exactly what i am trying to do !

do you have any idea on how ?

Can you either paste the full code by wrapping it in "code" tags or press the # above the smiley faces. It will be easier to read.
You can also paste it on pastebin

it is way to big to be posted in one post :frowning:

it doesn’t allow me to do so !

if you can read this one
http://www.instructables.com/files/orig/FWO/R38I/HQ9VUU35/FWOR38IHQ9VUU35.ino

this is the texter code

and this is the morse code

#include <avr/pgmspace.h>
#include <MorseEnDecoder.h>

// Pin mappings
const byte morseInPin = 2;      
const byte morseOutPin = 13;
// Instantiate Morse objects
morseDecoder morseInput(morseInPin, MORSE_KEYER, MORSE_ACTIVE_LOW);
morseEncoder morseOutput(morseOutPin);

// Variables dealing with formatting the output somewhat
// by inserting CR's (carriage returns)
long lastTransmissionTime;
long currentTime;
boolean transmissionEnded = true; // Flag to mark old transmission is finished

// Minimum transmission pause time to insert carriage returns (CR)
// Adjust depending on Morse speed. IE 13 wpm = 646 ms between words (no CR).
const long transmissionPaused   = 1000; // Suitable for 13 wpm?


void setup()
{
  Serial.begin(9600);
  Serial.println("Morse EnDecoder demo");
  
  // Setting Morse speed in wpm - words per minute
  // If not set, 13 wpm is default anyway
  morseInput.setspeed(13);
  morseOutput.setspeed(13);
  
  lastTransmissionTime = (long)millis();
}



void loop()
{
  currentTime = (long)millis();
  
  // Needs to call these once per loop
  morseInput.decode();
  morseOutput.encode();

  // SEND MORSE (OUTPUT)
  // Encode and send text received from the serial port (serial monitor)
  if (Serial.available() && morseOutput.available())
  {
    // Get character from serial and send as Morse code
    char sendMorse = Serial.read();
    morseOutput.write(sendMorse);
    // Not strictly needed, but used to get morseSignalString before it is destroyed
    // (E.g. for morse training purposes)
    morseOutput.encode();

    // Also write sent character + Morse code to serial port/monitor
    Serial.write(' ');
    Serial.write(sendMorse);
    Serial.write(morseOutput.morseSignalString);
  }


  // RECEIVE MORSE (INPUT)
  // If a character is decoded from the input, write it to serial port
  if (morseInput.available())
  {
    // Get decoded Morse code character and write it to serial port/monitor
    char receivedMorse = morseInput.read();
    Serial.print(receivedMorse);
    
    // A little error checking    
    if (receivedMorse == '#') Serial.println("< ERROR:too many morse signals! >");
  }


  // Local Morse code feedback from input if not sending Morse simultaneously
  if (morseOutput.available()) digitalWrite(morseOutPin, morseInput.morseSignalState);


  // Check if ongoing transmission (not yet transmission pause)
  if (!morseOutput.available() || morseInput.morseSignalState == true)
  {
    // reset last transmission timer and flag
    lastTransmissionTime = currentTime;
    transmissionEnded = false;
  }

  // Format output with carriage returns after a transmission pause
  if ((currentTime - lastTransmissionTime) > transmissionPaused)
  {
    if (transmissionEnded == false)
    {
      // Separate the transmissions somewhat in the serial monitor with CR's
      for (int cr=0; cr<2; cr++) Serial.println("");  // some carriage returns..
      
      // Finally set the flag to prevent continous carriage returns
      transmissionEnded = true;
    }
  }
}

pastebin for texter

well it is 4:45 am in Greece right now,

and my head is a mess at the momment.

last thing i did is pouting everything from EnDecoder inside the void loop of the texter i hear some bips but this is not morse.

probably it comunicates with the serial and speaker is connected to pin13.

i have no idea, and i am lost at the momment.

i am going for a good sleep to clear my head.

i really hope to see some good ideas on how to conbine those two by the time i wake up.

thanks for you time man.

Since you are merging two pieces of code and the text code working, what you want to do is enhance the outputserial() function.
This typedtext variable should contain the message you want to output as morse code which is a char array.

Create a new function…like ArrayToMorse that takes a char array as input and iterates through the array playing the morse code for the letter at array position as you go through the array.

Pseudocode:
void ArrayToMorse(char my_array){
for (int i = 0; i < length_of_array; i++){
switch i {
case A:
morse signal code
break;
case B:
morse signal code
break;
.
.
.
}

First of all i would like to declare to the world that there is nothing like a good sleep to clear you head.

had my shower and a bucket of morning coffee :smiley: and now i am ready to work.

thank you very much for your time man.

i saw that it needs some loops to do the ecncoding stuff. so i desided to creat a for loop like that inside my outputserial()

code is like that

void outputserial(){ //output message and display remaining characters to serial console
  for (int i=0; i<(positionintypedtext); i++){   // with this variant (positionintypedtext)it loops so many times, as many characters i have typed
  Serial.print(i);
  
  currentTime = (long)millis();
  
  // Needs to call these once per loop
  morseInput.decode();
  morseOutput.encode();

  // SEND MORSE (OUTPUT)
  // Encode and send text received from the serial port (serial monitor)
  
    // Get character from serial and send as Morse code
    char sendMorse = typedtext[i];
    morseOutput.write(sendMorse);
    Serial.print(' ');
    Serial.print(sendMorse);
    // Not strictly needed, but used to get morseSignalString before it is destroyed
    // (E.g. for morse training purposes)
    morseOutput.encode();

    // Also write sent character + Morse code to serial port/monitor
    Serial.write(' ');
    Serial.write(sendMorse);
    Serial.write(morseOutput.morseSignalString);
  


  // RECEIVE MORSE (INPUT)
  // If a character is decoded from the input, write it to serial port
  if (morseInput.available())
  {
    // Get decoded Morse code character and write it to serial port/monitor
    char receivedMorse = morseInput.read();
    Serial.print(receivedMorse);
    
    // A little error checking    
    if (receivedMorse == '#') Serial.println("< ERROR:too many morse signals! >");
  }


  // Local Morse code feedback from input if not sending Morse simultaneously
  if (morseOutput.available()) digitalWrite(morseOutPin, morseInput.morseSignalState);


  // Check if ongoing transmission (not yet transmission pause)
  if (!morseOutput.available() || morseInput.morseSignalState == true)
  {
    // reset last transmission timer and flag
    lastTransmissionTime = currentTime;
    transmissionEnded = false;
  }

  // Format output with carriage returns after a transmission pause
  if ((currentTime - lastTransmissionTime) > transmissionPaused)
  {
    if (transmissionEnded == false)
    {
      // Separate the transmissions somewhat in the serial monitor with CR's
      for (int cr=0; cr<2; cr++) Serial.println("");  // some carriage returns..
      
      // Finally set the flag to prevent continous carriage returns
      transmissionEnded = true;
    }
  }
}
  delay(preventholddelay); //delay a little to prevent continuous cycling
}

no bips at all.

serial print though is warking fine
0 A A.-1 M M.-2 J J.-3 T T.-4 W W.-5 P P.-6 G G.-

first it print the value of i
then the letter in sendMorse
and then the letterwith morse code right next.
so for loop working just fine,
the library recognise the char and decodes it to serial with the apropriate . and - !
BUT NO BIPS. :slight_smile:
ANY IDEA ON WHY ?

i included everything from the morse EnDecoder code ( that works realy fine with my setup) inside the outputserial() Function

here is the code

void outputserial(){ //output message and display remaining characters to serial console
  #include <avr/pgmspace.h>
#include <MorseEnDecoder.h>

// Pin mappings
const byte morseInPin = 2;      
const byte morseOutPin = 13;
// Instantiate Morse objects
morseDecoder morseInput(morseInPin, MORSE_KEYER, MORSE_ACTIVE_LOW);
morseEncoder morseOutput(morseOutPin);

// Variables dealing with formatting the output somewhat
// by inserting CR's (carriage returns)
long lastTransmissionTime;
long currentTime;
boolean transmissionEnded = true; // Flag to mark old transmission is finished

// Minimum transmission pause time to insert carriage returns (CR)
// Adjust depending on Morse speed. IE 13 wpm = 646 ms between words (no CR).
const long transmissionPaused   = 1000; // Suitable for 13 wpm?
 
  // Setting Morse speed in wpm - words per minute
  // If not set, 13 wpm is default anyway
  morseInput.setspeed(13);
  morseOutput.setspeed(13);
  
  lastTransmissionTime = (long)millis(); 
 
  for (int i=0; i<(positionintypedtext); i++){
  Serial.print(i);
  
  currentTime = (long)millis();
  
  // Needs to call these once per loop
  morseInput.decode();
  morseOutput.encode();

  // SEND MORSE (OUTPUT)
  // Encode and send text received from the serial port (serial monitor)
  
    // Get character from serial and send as Morse code
    char sendMorse = typedtext[i];
    morseOutput.write(sendMorse);
    Serial.print(' ');
    Serial.print(sendMorse);
    // Not strictly needed, but used to get morseSignalString before it is destroyed
    // (E.g. for morse training purposes)
    morseOutput.encode();

    // Also write sent character + Morse code to serial port/monitor
    Serial.write(' ');
    Serial.write(sendMorse);
    Serial.write(morseOutput.morseSignalString);
  


  // RECEIVE MORSE (INPUT)
  // If a character is decoded from the input, write it to serial port
  if (morseInput.available())
  {
    // Get decoded Morse code character and write it to serial port/monitor
    char receivedMorse = morseInput.read();
    Serial.print(receivedMorse);
    
    // A little error checking    
    if (receivedMorse == '#') Serial.println("< ERROR:too many morse signals! >");
  }


  // Local Morse code feedback from input if not sending Morse simultaneously
  if (morseOutput.available()) digitalWrite(morseOutPin, morseInput.morseSignalState);


  // Check if ongoing transmission (not yet transmission pause)
  if (!morseOutput.available() || morseInput.morseSignalState == true)
  {
    // reset last transmission timer and flag
    lastTransmissionTime = currentTime;
    transmissionEnded = false;
  }

  // Format output with carriage returns after a transmission pause
  if ((currentTime - lastTransmissionTime) > transmissionPaused)
  {
    if (transmissionEnded == false)
    {
      // Separate the transmissions somewhat in the serial monitor with CR's
      for (int cr=0; cr<2; cr++) Serial.println("");  // some carriage returns..
      
      // Finally set the flag to prevent continous carriage returns
      transmissionEnded = true;
    }
  }
  Serial.println();
}
  delay(preventholddelay); //delay a little to prevent continuous cycling
}

i inputed a random text “BKMDBZ” to my LCD and pressed the enter key, with the serial window open and this came up
0 B B-…
1 K K-…
2 M M-…
3 D D-…
4 B B-…
5 Z Z-…

but have no bips to my speaker at all.

shouldn’t that work just fine ?

does anyone have an idea why ?

well it worked parcialy ok and i have bips

here is the code

void outputserial(){ //output message and display remaining characters to serial console
  for (int i=0; i<(positionintypedtext); i++){
  #include <pgmspace.h>
#include <MorseEnDecoder.h>

// Pin mappings
const byte morseInPin = 2;      
const byte morseOutPin = 13;
// Instantiate Morse objects
morseDecoder morseInput(morseInPin, MORSE_KEYER, MORSE_ACTIVE_LOW);
morseEncoder morseOutput(morseOutPin);

// Variables dealing with formatting the output somewhat
// by inserting CR's (carriage returns)
long lastTransmissionTime;
long currentTime;
boolean transmissionEnded = true; // Flag to mark old transmission is finished

// Minimum transmission pause time to insert carriage returns (CR)
// Adjust depending on Morse speed. IE 13 wpm = 646 ms between words (no CR).
const long transmissionPaused   = 1000; // Suitable for 13 wpm?
 
  // Setting Morse speed in wpm - words per minute
  // If not set, 13 wpm is default anyway
  morseInput.setspeed(13);
  morseOutput.setspeed(13);
  
  lastTransmissionTime = (long)millis(); 
 
    Serial.println();
    Serial.print(i);
  
  currentTime = (long)millis();
  
  // Needs to call these once per loop
  morseInput.decode();
  morseOutput.encode();

  // SEND MORSE (OUTPUT)
  // Encode and send text received from the serial port (serial monitor)
  
    // Get character from serial and send as Morse code
    char sendMorse = typedtext[i];
    morseOutput.write(sendMorse);
    Serial.print(' ');
    Serial.print(sendMorse);
    // Not strictly needed, but used to get morseSignalString before it is destroyed
    // (E.g. for morse training purposes)
    morseOutput.encode();

    // Also write sent character + Morse code to serial port/monitor
    Serial.write(' ');
    Serial.write(sendMorse);
    Serial.write(morseOutput.morseSignalString);
  


  // RECEIVE MORSE (INPUT)
  // If a character is decoded from the input, write it to serial port
  if (morseInput.available())
  {
    // Get decoded Morse code character and write it to serial port/monitor
    char receivedMorse = morseInput.read();
    Serial.print(receivedMorse);
    
    // A little error checking    
    if (receivedMorse == '#') Serial.println("< ERROR:too many morse signals! >");
  }


  // Local Morse code feedback from input if not sending Morse simultaneously
  if (morseOutput.available()) digitalWrite(morseOutPin, morseInput.morseSignalState);


  // Check if ongoing transmission (not yet transmission pause)
  if (!morseOutput.available() || morseInput.morseSignalState == true)
  {
    // reset last transmission timer and flag
    lastTransmissionTime = currentTime;
    transmissionEnded = false;
  }

  // Format output with carriage returns after a transmission pause
  if ((currentTime - lastTransmissionTime) > transmissionPaused)
  {
    if (transmissionEnded == false)
    {
      // Separate the transmissions somewhat in the serial monitor with CR's
      for (int cr=0; cr<2; cr++) Serial.println("");  // some carriage returns..
      
      // Finally set the flag to prevent continous carriage returns
      transmissionEnded = true;
    }
  }
  }
   //delay a little to prevent continuous cycling
}

morse decode is just fine here is an utput of a random text
0 E E.
1 N N-.
2 K K-.-
3 T T-
4 W W.–
5 M M–
6 D D-…
0 E E.
1 N N-.
2 K K-.-
3 T T-
4 W W.–
5 M M–
6 D D-…
7 J J.—
8 U U…-
9 W W.–
10 M M–
11 D D-…
12 A A.-
13 K K-.-
14 H H…
15 Q Q–.-
16 B B-…
17 D D-…
18 N N-.
19 X X-…-
20 U U…-
21 J J.—
22 M M–
23 E E.
24 B B-…
25 Z Z–…
26 R R.-.

but everything works so fast, like 1000 words per minute.

any one has any idea ?

Are you using PWM for the audio? It probably works fast because that's how quickly it's scanning the letters and playing them out, you would need to add a delay or a timer function of some kind.

kourpetis, if you don't know multi-tasking on Arduino then a very good start is here:

The next step is to look up finite state machine tutorials. The ideas are simple but can be made complex to cover complex needs... with practice and invention.

With techniques like FSM you can combine different codes without having to mix the codes themselves. Each part has an if() or other logic you write so that it only runs on conditions you set. State machine uses a variable to control what step(s) to run on any single pass through loop().
The state variable may be changed at any time to reflect a change in the process or environment that causes a need for different code to run. As long as you keep short what piece of the code runs in the NOW of loop(), your code will always be responsive to time and inputs.

Passing information from one section of code to another saves you from having to "weave" different codes together which from long experience I can tell you is the path to spaghetti-code, also known as the can of worms that every time you open takes a bigger can to put all the worms back in. It is a very messy way to code and has caused more baldness than perhaps birth genetics.

Your number pad code would read the keys and when entry is finished, put the value into a variable and set the state to run the display code which would read the value variable and display that then set the state back to watching the keypad and reading new input.

Just don't have a code loop (inside of loop()) that reads a pin until it senses a button even if right now you don't need to do anything else. Why not? because if you want to add a third function to your project, it will be harder and need rewriting that pin read and likely much after that seemed like the way to go before.

Use loop() to repeatedly check or do anything not time critical down to microseconds or less. When you want or need to add a new thing, it will then have a chance to run shortly. Time goes on, loop() goes around like a wheel, you don't have to do everything in one pass through loop() as that's a slow turning wheel with no chance to check time or sensors often enough to be responsive.