morse code

/* 
10   
11 //Choose the pin that has the LED connected to it 
12 const int led = 13; 
13 
 
14 //Morse Code Timings - change as desired 
15 const double MULTIPLIER = 2.5; //Increase durations of dots/dashes 
16 const double DOT = 92.3 * MULTIPLIER; //1 dot 
17 const double DASH = 276.9 * MULTIPLIER; //3 dots 
18 const double TIMING_SPACE = 92.3 * MULTIPLIER; //1 dot: space between dots/dashes 
19 const double CHAR_SPACE = 276.9 * MULTIPLIER; //3 dots: space between characters 
20 const double WORD_SPACE = 646.1; //7 dots - space between words 
21 
 
22 //Morse Code timings holder array setup 
23 const int NUM_CHARS = 96; 
24 const int MORSE_MAX_CHAR_SIZE = 7; 
25 
 
26 //Array placement is based on a character's ASCII value 
27 //IF YOU ADD A NEW VALUE BE SURE TO ADD IT TO THE ACCEPTED CHAR ERROR CHECK 
28 //Note: since there is no difference between lower/upper case in Morse,  
29 //only upper is entered here - lower case is converted to upper using ASCII 
30 int TIMINGS[NUM_CHARS][MORSE_MAX_CHAR_SIZE] = { 
31  {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},  
32  {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},  
33  {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},  
34  {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},  
35  {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},  
36  {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},  
37  {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},  
38  {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},  
39  {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},  
40  {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},  
41  {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, 
42  {DASH, DOT, DASH, DOT, DASH, DASH, 0}, //! 
43  {DOT, DASH, DOT, DOT, DASH, DOT, 0}, //" 
44  {0, 0, 0, 0, 0, 0, 0}, 
45  {DOT, DOT, DOT, DASH, DOT, DOT, DASH}, //$ 
46  {0, 0, 0, 0, 0, 0, 0}, 
47  {DOT, DASH, DOT, DOT, DOT, 0, 0}, //& 
48  {DOT, DASH, DASH, DASH, DASH, DOT, 0}, //' 
49  {DASH, DOT, DASH, DASH, DOT, 0, 0}, //( 
50  {DASH, DOT, DASH, DASH, DOT, DASH, 0}, //) 
51  {0, 0, 0, 0, 0, 0, 0}, 
52  {DOT, DASH, DOT, DASH, DOT, 0, 0}, //+ 
53  {DASH, DASH, DOT, DOT, DASH, DASH, 0}, //, 
54  {DASH, DOT, DOT, DOT, DOT, DASH, 0}, //- 
55  {DOT, DASH, DOT, DASH, DOT, DASH, 0}, //. 
56  {DASH, DOT, DOT, DASH, DOT, 0, 0}, /// 
57  {DASH, DASH, DASH, DASH, DASH, 0, 0}, //0 
58  {DOT, DASH, DASH, DASH, DASH, 0, 0}, //1 
59  {DOT, DOT, DASH, DASH, DASH, 0, 0}, //2 
60  {DOT, DOT, DOT, DASH, DASH, 0, 0}, //3 
61  {DOT, DOT, DOT, DOT, DASH, 0, 0}, //4 
62  {DOT, DOT, DOT, DOT, DOT, 0, 0}, //5 
63  {DASH, DOT, DOT, DOT, DOT, 0, 0}, //6 
64  {DASH, DASH, DOT, DOT, DOT, 0, 0}, //7 
65  {DASH, DASH, DASH, DOT, DOT, 0, 0}, //8 
66  {DASH, DASH, DASH, DASH, DOT, 0, 0}, //9 
67  {DASH, DASH, DASH, DOT, DOT, DOT, 0}, //: 
68  {DASH, DOT, DASH, DOT, DASH, DOT, 0}, //; 
69  {0, 0, 0, 0, 0, 0, 0}, 
70  {DASH, DOT, DOT, DOT, DASH, 0, 0}, //= 
71  {0, 0, 0, 0, 0, 0, 0}, 
72  {DOT, DOT, DASH, DASH, DOT, DOT, 0}, //? 
73  {DOT, DASH, DASH, DOT, DASH, DOT, 0}, //@ 
74  {DOT, DASH, 0, 0, 0, 0, 0}, //A 
75  {DASH, DOT, DOT, DOT, 0, 0, 0}, //B 
76  {DASH, DOT, DASH, DOT, 0, 0, 0}, //C 
77  {DASH, DOT, DOT, 0, 0, 0, 0}, //D 
78  {DOT, 0, 0, 0, 0, 0, 0}, //E 
79  {DOT, DOT, DASH, DOT, 0, 0, 0}, //F 
80  {DASH, DASH, DOT, 0, 0, 0, 0}, //G 
81  {DOT, DOT, DOT, DOT, 0, 0, 0}, //H 
82  {DOT, DOT, 0, 0, 0, 0, 0}, //I 
83  {DOT, DASH, DASH, DASH, 0, 0, 0}, //J 
84  {DASH, DOT, DASH, 0, 0, 0, 0}, //K 
85  {DOT, DASH, DOT, DOT, 0, 0, 0}, //L 
86  {DASH, DASH, 0, 0, 0, 0, 0}, //M 
87  {DASH, DOT, 0, 0, 0, 0, 0}, //N 
88  {DASH, DASH, DASH, 0, 0, 0, 0}, //O 
89  {DOT, DASH, DASH, DOT, 0, 0, 0}, //P 
90  {DASH, DASH, DOT, DASH, 0, 0, 0}, //Q 
91  {DOT, DASH, DOT, 0, 0, 0, 0}, //R 
92  {DOT, DOT, DOT, 0, 0, 0, 0}, //S 
93  {DASH, 0, 0, 0, 0, 0, 0}, //T 
94  {DOT, DOT, DASH, 0, 0, 0, 0}, //U 
95  {DOT, DOT, DOT, DASH, 0, 0, 0}, //V 
96  {DOT, DASH, DASH, 0, 0, 0, 0}, //W 
97  {DASH, DOT, DOT, DASH, 0, 0, 0}, //X 
98  {DASH, DOT, DASH, DASH, 0, 0, 0}, //Y 
99  {DASH, DASH, DOT, DOT, 0, 0, 0}, //Z 
100   {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, 
101   {0, 0, 0, 0, 0, 0, 0}, 
102   {DOT, DOT, DASH, DASH, DOT, DASH, 0}, //_ 
103 }; 
104 
 
105 //The setup routine runs once when you press reset: 
106 void setup() {                 
107   //Initialize the digital pin as an output 
108   pinMode(led, OUTPUT); 
109 
 
110   //Initialize Serial 
111   Serial.begin(9600); 
112 } 
113 
 
114 //Basic linked-list node implementation  
115 struct node { 
116   char value; 
117   struct node *next; 
118 }; 
119 
 
120 //The loop routine runs in an infinite loop: 
121 void loop() {  
122   //Ask the user for the string 
123   Serial.println("Send text to be displayed in Morse Code"); 
124 
 
125   //Wait until the user has entered data 
126   while(Serial.available() == 0); 
127 
 
128   //Give Serial a chance to read all the bytes 
129   delay(100); 
130    
131   //Setup the list 
132   struct node *root, *currentNode; 
133   root = (struct node*)malloc(sizeof(struct node)); 
134   root->value = '\0'; 
135   root->next = 0; 
136   currentNode = root; 
137 
 
138   //Read the user input 
139   while(Serial.available() > 0) { 
140     currentNode->next = (struct node*)malloc(sizeof(struct node)); 
141     currentNode = currentNode->next; 
142     currentNode->value = Serial.read(); 
143     currentNode->next = 0; 
144   } 
145   currentNode = root; 
146    
147   //Display the user input back to the user 
148   Serial.println("Displaying: "); 
149   while(currentNode->next != 0) { 
150     currentNode = currentNode->next; 
151     Serial.print(currentNode->value); 
152   } 
153   Serial.println(); 
154   currentNode = root;   
155    
156   //Go through all  nodes and display characters in Morse Code via the LED 
157   while(currentNode->next != 0) { 
158     //Move to the next character 
159     currentNode = currentNode->next; 
160 
 
161     //Get the ASCII value of the character being looked at 
162     int ASCII = currentNode->value; 
163 
 
164     //Convert lower case letters to upper case 
165     if(ASCII >= 97 && ASCII <= 122) { 
166       ASCII = ASCII - 32; 
167     } 
168      
169     //Ensure the character is one that has been programmed in for Morse 
170     if((ASCII >= 32 && ASCII <= 34) || ASCII == 36 ||  
171        (ASCII >= 38 && ASCII <= 41) || (ASCII >= 43 && ASCII <= 59) || 
172        ASCII == 61 || (ASCII >= 63 && ASCII <= 90) || ASCII == 95) {       
173       //If the character is a space 
174       if(ASCII == 32) { 
175         delay(WORD_SPACE); 
176       } else { 
177         //Go through the timing sequence for each character 
178         for(int i = 0; i < MORSE_MAX_CHAR_SIZE; ++i) {  
179           //If the timing sequence is over, break the loop 
180           if(TIMINGS[ASCII][i] == 0) { 
181             break; 
182           } else { //Display the timing sequence on the LED 
183             digitalWrite(led, HIGH); 
184             delay(TIMINGS[ASCII][i]); 
185             digitalWrite(led, LOW); 
186             delay(TIMING_SPACE); 
187           } 
188         }  
189       }   
190     } else { 
191       Serial.print("'"); 
192       Serial.print(currentNode->value); 
193       Serial.print("' does not have a Morse Code timing. Skipping it."); 
194       Serial.println(); 
195     } 
196     delay(CHAR_SPACE); 
197   } 
198 }

the above code I would like to know if any body can make it work with more than 1 led max 8 each flashing the next letter In the sequence

Yes, but we won't. Try it yourself and when there is a problem a google search doesn't solve, ask.

lg, couka

I am trying to , but I am struggling ,
this is why I asked for help

No, you're not asking for help, your asking for someone to do this for you.
Tell us what you tried and what doesn't work.

lg, couka

I duplicated this line
12 const int led = 13;
13 const int led = 9;

const int led = 13;
I have also tried const int led = 9,13;

You can't have two entities with the same name in the same scope - how would you know which one to address?

Please omit the line numbers when posting code.

sorry about line numbers, as you can see I am a beginner , I am trying ,

//Choose the pin that has the LED connected to it
const int led =  9;



//Morse Code Timings - change as desired
const double MULTIPLIER = 2.5; //Increase durations of dots/dashes
const double DOT = 92.3 * MULTIPLIER; //1 dot
const double DASH = 276.9 * MULTIPLIER; //3 dots
const double TIMING_SPACE = 92.3 * MULTIPLIER; //1 dot: space between dots/dashes
const double CHAR_SPACE = 276.9 * MULTIPLIER; //3 dots: space between characters
const double WORD_SPACE = 646.1; //7 dots - space between words


//Morse Code timings holder array setup
const int NUM_CHARS = 96;
const int MORSE_MAX_CHAR_SIZE = 7;


//Array placement is based on a character's ASCII value
//IF YOU ADD A NEW VALUE BE SURE TO ADD IT TO THE ACCEPTED CHAR ERROR CHECK
//Note: since there is no difference between lower/upper case in Morse,
//only upper is entered here - lower case is converted to upper using ASCII
int TIMINGS[NUM_CHARS][MORSE_MAX_CHAR_SIZE] = {
  {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},
  {DASH, DOT, DASH, DOT, DASH, DASH, 0}, //!
  {DOT, DASH, DOT, DOT, DASH, DOT, 0}, //"
  {0, 0, 0, 0, 0, 0, 0},
  {DOT, DOT, DOT, DASH, DOT, DOT, DASH}, //$
  {0, 0, 0, 0, 0, 0, 0},
  {DOT, DASH, DOT, DOT, DOT, 0, 0}, //&
  {DOT, DASH, DASH, DASH, DASH, DOT, 0}, //'
  {DASH, DOT, DASH, DASH, DOT, 0, 0}, //(
  {DASH, DOT, DASH, DASH, DOT, DASH, 0}, //)
  {0, 0, 0, 0, 0, 0, 0},
  {DOT, DASH, DOT, DASH, DOT, 0, 0}, //+
  {DASH, DASH, DOT, DOT, DASH, DASH, 0}, //,
  {DASH, DOT, DOT, DOT, DOT, DASH, 0}, //-
  {DOT, DASH, DOT, DASH, DOT, DASH, 0}, //.
  {DASH, DOT, DOT, DASH, DOT, 0, 0}, ///
  {DASH, DASH, DASH, DASH, DASH, 0, 0}, //0
  {DOT, DASH, DASH, DASH, DASH, 0, 0}, //1
  {DOT, DOT, DASH, DASH, DASH, 0, 0}, //2
  {DOT, DOT, DOT, DASH, DASH, 0, 0}, //3
  {DOT, DOT, DOT, DOT, DASH, 0, 0}, //4
  {DOT, DOT, DOT, DOT, DOT, 0, 0}, //5
  {DASH, DOT, DOT, DOT, DOT, 0, 0}, //6
  {DASH, DASH, DOT, DOT, DOT, 0, 0}, //7
  {DASH, DASH, DASH, DOT, DOT, 0, 0}, //8
  {DASH, DASH, DASH, DASH, DOT, 0, 0}, //9
  {DASH, DASH, DASH, DOT, DOT, DOT, 0}, //:
  {DASH, DOT, DASH, DOT, DASH, DOT, 0}, //;
  {0, 0, 0, 0, 0, 0, 0},
  {DASH, DOT, DOT, DOT, DASH, 0, 0}, //=
  {0, 0, 0, 0, 0, 0, 0},
  {DOT, DOT, DASH, DASH, DOT, DOT, 0}, //?
  {DOT, DASH, DASH, DOT, DASH, DOT, 0}, //@
  {DOT, DASH, 0, 0, 0, 0, 0}, //A
  {DASH, DOT, DOT, DOT, 0, 0, 0}, //B
  {DASH, DOT, DASH, DOT, 0, 0, 0}, //C
  {DASH, DOT, DOT, 0, 0, 0, 0}, //D
  {DOT, 0, 0, 0, 0, 0, 0}, //E
  {DOT, DOT, DASH, DOT, 0, 0, 0}, //F
  {DASH, DASH, DOT, 0, 0, 0, 0}, //G
  {DOT, DOT, DOT, DOT, 0, 0, 0}, //H
  {DOT, DOT, 0, 0, 0, 0, 0}, //I
  {DOT, DASH, DASH, DASH, 0, 0, 0}, //J
  {DASH, DOT, DASH, 0, 0, 0, 0}, //K
  {DOT, DASH, DOT, DOT, 0, 0, 0}, //L
  {DASH, DASH, 0, 0, 0, 0, 0}, //M
  {DASH, DOT, 0, 0, 0, 0, 0}, //N
  {DASH, DASH, DASH, 0, 0, 0, 0}, //O
  {DOT, DASH, DASH, DOT, 0, 0, 0}, //P
  {DASH, DASH, DOT, DASH, 0, 0, 0}, //Q
  {DOT, DASH, DOT, 0, 0, 0, 0}, //R
  {DOT, DOT, DOT, 0, 0, 0, 0}, //S
  {DASH, 0, 0, 0, 0, 0, 0}, //T
  {DOT, DOT, DASH, 0, 0, 0, 0}, //U
  {DOT, DOT, DOT, DASH, 0, 0, 0}, //V
  {DOT, DASH, DASH, 0, 0, 0, 0}, //W
  {DASH, DOT, DOT, DASH, 0, 0, 0}, //X
  {DASH, DOT, DASH, DASH, 0, 0, 0}, //Y
  {DASH, DASH, DOT, DOT, 0, 0, 0}, //Z
  {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0},
  {DOT, DOT, DASH, DASH, DOT, DASH, 0}, //_

};


//The setup routine runs once when you press reset:
void setup() {
  //Initialize the digital pin as an output
  pinMode(led, OUTPUT);

  //Initialize Serial
  Serial.begin(9600);

}


//Basic linked-list node implementation
struct node {
  char value;
  struct node *next;

};


//The loop routine runs in an infinite loop:
void loop() {
  //Ask the user for the string
  Serial.println("Send text to be displayed in Morse Code");


  //Wait until the user has entered data
  while (Serial.available() == 0);


  //Give Serial a chance to read all the bytes
  delay(100);

  //Setup the list
  struct node *root, *currentNode;
  root = (struct node*)malloc(sizeof(struct node));
  root->value = '\0';
  root->next = 0;
  currentNode = root;


  //Read the user input
  while (Serial.available() > 0) {
    currentNode->next = (struct node*)malloc(sizeof(struct node));
    currentNode = currentNode->next;
    currentNode->value = Serial.read();
    currentNode->next = 0;

  }
  currentNode = root;

  //Display the user input back to the user
  Serial.println("Displaying: ");
  while (currentNode->next != 0) {
    currentNode = currentNode->next;
    Serial.print(currentNode->value);

  }
  Serial.println();
  currentNode = root;

  //Go through all  nodes and display characters in Morse Code via the LED
  while (currentNode->next != 0) {
    //Move to the next character
    currentNode = currentNode->next;


    //Get the ASCII value of the character being looked at
    int ASCII = currentNode->value;


    //Convert lower case letters to upper case
    if (ASCII >= 97 && ASCII <= 122) {
      ASCII = ASCII - 32;

    }

    //Ensure the character is one that has been programmed in for Morse
    if ((ASCII >= 32 && ASCII <= 34) || ASCII == 36 ||
        (ASCII >= 38 && ASCII <= 41) || (ASCII >= 43 && ASCII <= 59) ||
        ASCII == 61 || (ASCII >= 63 && ASCII <= 90) || ASCII == 95) {
      //If the character is a space
      if (ASCII == 32) {
        delay(WORD_SPACE);

      } else {
        //Go through the timing sequence for each character
        for (int i = 0; i < MORSE_MAX_CHAR_SIZE; ++i) {
          //If the timing sequence is over, break the loop
          if (TIMINGS[ASCII][i] == 0) {
            break;

          } else { //Display the timing sequence on the LED
            digitalWrite(led, HIGH);
            delay(TIMINGS[ASCII][i]);
            digitalWrite(led, LOW);
            delay(TIMING_SPACE);

          }

        }

      }

    } else {
      Serial.print("'");
      Serial.print(currentNode->value);
      Serial.print("' does not have a Morse Code timing. Skipping it.");
      Serial.println();

    }
    delay(CHAR_SPACE);

  }

}

Your TIMINGS array is a huge waste of precious RAM.

I might be inclined to write a class to drive a single LED with a single given letter, and then have an array of objects of that class.

what did you say told you I was a beginner