Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need an arduino code to do the following •Your program will accept a number from

ID: 3704145 • Letter: N

Question

Need an arduino code to do the following

•Your program will accept a number from the user over the serial port. If the number sent is between 1 and 5, you are to have the Morse Code signal for that number displayed on the LED.

•You should represent your Morse Code signals in a 2-D array. You should declare a 2-D array by using: e.g. int myArray[5][5]; - this is like a matrix with the first index indicating the number being represented and the second index indicating for each element in the code whether it is 25% of the duty cycle (dot) or 75% of the duty cycle (dash). The rate of transmission of an element in a code is 5 Hz.

     YOU SHOULD GENERATE THIS 2-D ARRAY USING AN ALGORITHM IN A LOOP

     NOTING THE PATTERN OF THE SIGNALS BETWEEN 1 AND 5. YOU SHOULD NOT

     EXPLICITLY ASSIGN THE ELEMENTS FOR EACH NUMBER SEPARATELY.

•You should display the number on the LED only once.

•You should show the calculations needed to determine your resistor value for the circuit. The specs for your LEDs are: 15 mA forward current, 2.2 V forward voltage

Explanation / Answer

//Morse Code signal for that number displayed on the LED.

//Create constant array of the messages you want Morse'd out

const char message[ ]="SOS";

// In ASCII code, 'space' is 32, '0'-'9' is 48-57, and 'A'-'Z' is 65-90
const String morse[] = { ".----", "..---", "...--", "....-", ".....",
"-....", "--...", "---..", "----.", "-----", ".-", "-...", "-.-.", "-..",
".","..-.","--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---",
".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--",
"--.."};

const byte led = 13;
const byte speaker = A5; // LED
const int dotLen = 200; //delay in milliseconds
const int dashLen = 3*dotLen; // 3X longer than the dot
const int wordLen = 7*dotLen; // space between words.

void setup() {
pinMode(led, OUTPUT);   
pinMode(speaker, OUTPUT);
}

// blink out one morse code character.
void signalMorse(String c) {
int i = 0;
while (c[i]) { // for each dot or dash in the letter...
digitalWrite(led,HIGH); // turn the LED on
tone(speaker, 450); // speaker plays a tone of 450 hertz
if (c[i] == '.') {
delay(dotLen); // if dot, short delay
} else if (c[i] == '-') {
delay(dashLen); // if dash, longer delay
}
digitalWrite(led,LOW); //LED off
noTone(speaker); // speaker off
delay(dotLen);
i++; //bring in the next dot or dash from the morse letter!]'
};
// We already delayed one dot length in the loop. A Word break = dashLen..
delay(dashLen-dotLen);
}

void loop() {
int i = 0; //counter variable to move through the array
char C; //holds each letter as it gets converted to blinks
while (message[i]) { // fails when reaches the end of the string ("0")
C = toupper(message[i]);
  
if (C == ' ') {
delay(wordLen); // space between words  
}
else if (C>47 && C<58) { // 0-9. ASCII 48-57
signalMorse(morse[C-48]);
}
else if (C>64 && C<91) { // A-Z, ASCII 65-90, 10-34 in morse[]
signalMorse(morse[C-55]);
}
else {
delay(wordLen);
}
i++; // move to the next character in your message
}
delay(2 * wordLen);
}

//Morse Code signals in a 2-D array.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote