I am trying to create a project that converts a String that is entered at the top of the code into a series of on and off flashes of an LED (plugged into the D13 pin). The IDE does not report any syntax errors, but the code does not work.
#include "Morse.h"
String stuff = "Hello, world";
//Note: use "*" for apostrophe
byte pinNo = 13;
int dit = 750;
void morseWrite(char letter) {
String thatLetter = MDefault;
switch (letter) {
case 'a':
thatLetter = Ma;
break;
case 'b':
thatLetter = Mb;
break;
case 'c':
thatLetter = Mc;
break;
case 'd':
thatLetter = Md;
break;
case 'e':
thatLetter = Me;
break;
case 'f':
thatLetter = Mf;
break;
case 'g':
thatLetter = Mg;
break;
case 'h':
thatLetter = Mh;
break;
case 'i':
thatLetter = Mi;
break;
case 'j':
thatLetter = Mj;
break;
case 'k':
thatLetter = Mk;
break;
case 'l':
thatLetter = Ml;
break;
case 'm':
thatLetter = Mm;
break;
case 'n':
thatLetter = Mn;
break;
case 'o':
thatLetter = Mo;
break;
case 'p':
thatLetter = Mp;
break;
case 'q':
thatLetter = Mq;
break;
case 'r':
thatLetter = Mr;
break;
case 's':
thatLetter = Ms;
break;
case 't':
thatLetter = Mt;
break;
case 'u':
thatLetter = Mu;
break;
case 'v':
thatLetter = Mv;
break;
case 'w':
thatLetter = Mw;
break;
case 'x':
thatLetter = Mx;
break;
case 'y':
thatLetter = My;
break;
case 'z':
thatLetter = Mz;
break;
case '0':
thatLetter = M0;
break;
case '1':
thatLetter = M1;
break;
case '2':
thatLetter = M2;
break;
case '3':
thatLetter = M3;
break;
case '4':
thatLetter = M4;
break;
case '5':
thatLetter = M5;
break;
case '6':
thatLetter = M6;
break;
case '7':
thatLetter = M7;
break;
case '8':
thatLetter = M8;
break;
case '9':
thatLetter = M9;
break;
case '.':
thatLetter = MPer;
break;
case ',':
thatLetter = MCom;
break;
case '?':
thatLetter = MQues;
break;
case '*':
thatLetter = MApos;
break;
case '!':
thatLetter = MExc;
break;
case '/':
thatLetter = MSlsh;
break;
case '(':
thatLetter = MPar;
break;
case ')':
thatLetter = MClos;
break;
case '&':
thatLetter = MAmp;
break;
case ':':
thatLetter = MCol;
break;
case ';':
thatLetter = MSemi;
break;
case '=':
thatLetter = MEqu;
break;
case '+':
thatLetter = MPls;
break;
case '-':
thatLetter = MMin;
break;
case '_':
thatLetter = MUnd;
break;
case '"':
thatLetter = MQuot;
break;
case '
Also, I created a library (Morse.h) that converts each character to a series of 0s (dots), 1s (dashes), 2s (these are filler characters), and 3s (to denote a space). This is below:
#define Ma "012222"
#define Mb "100022"
#define Mc "101022"
#define Md "100222"
#define Me "022222"
#define Mf "001022"
#define Mg "110222"
#define Mh "000022"
#define Mi "002222"
#define Mj "011122"
#define Mk "101222"
#define Ml "010022"
#define Mm "112222"
#define Mn "102222"
#define Mo "111222"
#define Mp "011022"
#define Mq "110122"
#define Mr "010222"
#define Ms "000222"
#define Mt "122222"
#define Mu "001222"
#define Mv "000122"
#define Mw "011222"
#define Mx "100122"
#define My "101122"
#define Mz "110022"
#define M0 "111112"
#define M1 "011112"
#define M2 "001112"
#define M3 "000112"
#define M4 "000012"
#define M5 "000002"
#define M6 "100002"
#define M7 "110002"
#define M8 "111002"
#define M9 "111102"
#define MPer "010101"
#define MCom "110011"
#define MQues "001100"
#define MApos "011110"
#define MExc "101011"
#define MSlsh "100102"
#define MPar "101102"
#define MClos "101101"
#define MAmp "010002"
#define MCol "111000"
#define MSemi "101010"
#define MEqu "100012"
#define MPls "010102"
#define MMin "100001"
#define MUnd "001101"
#define MQuot "010010"
#define MDol "0001001"
#define MAt "011010"
#define MSpac "322222"
#define MDefault "222222"
Finally, I was wondering if it is necessary for the massive switch statement to exist or if there is a more efficient way to perform the same task.:
thatLetter = MDol;
break;
case '@':
thatLetter = MAt;
break;
case ' ':
thatLetter = MSpac;
break;
default:
thatLetter = MDefault;
}
for(byte b = 1; b > 7; b++) {
char beep = thatLetter.charAt(b);
switch (beep) {
case '0':
digitalWrite(pinNo, HIGH);
delay(dit);
digitalWrite(pinNo, LOW);
delay(dit);
break;
case '1':
digitalWrite(pinNo, HIGH);
delay(dit3);
digitalWrite(pinNo, LOW);
delay(dit);
break;
case '3':
delay(dit4);
}
delay(dit*3);
}
}
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
stuff.toLowerCase();
byte length = stuff.length();
length += 1;
for(int i = 1; i < length; i++) {
char daLetter = stuff.charAt(i);
morseWrite(daLetter);
}
}
Also, I created a library (Morse.h) that converts each character to a series of 0s (dots), 1s (dashes), 2s (these are filler characters), and 3s (to denote a space). This is below:
§DISCOURSE_HOISTED_CODE_1§
Finally, I was wondering if it is necessary for the massive switch statement to exist or if there is a more efficient way to perform the same task.