Just to confirm, do you have the selection reading LOW when selected, and pin10 which is still set HIGH outputting 5v is not connected to the selector switch.
There are issues with the call sign and the random number. I have added some comments to the code and made some revisions. You need to address the mCode char* by index.
Let me know about the call sign you want, and work on the random number issue. I'm not certain you can do it with the character array pointers as written.
//Software details, only edit lines with editme tags
//OTMK Version 1.1.0
//Version date: 3/28/22
//Contributors: Jeremy E
//Software not to be edited by anyone other than OTMK Moderators, OTMK Administrators or OTMK Engineers
//Hello?
//Dad? Is that you?
//Initialize SWAN Protocall
//Warning
//***entered***4 8 15 16 23 42
//WALT?!
//WALT!
//editme
char callSign[] = "Test Call Sign"; //is this what you want sent or the mCode pointer?
//editme
unsigned int led_pin = 13;
const int buzzer = 2;
const int buttonPin = 10;
const int Pinone = 3;
const int Pintwo = 4;
const int Pinthr = 5;
const int Pinfou = 6;
const int Pinfiv = 7;
const int Pinsix = 8;
long randNumber;
// Declare an array named letters that holds addresses of string literals
// (i.e. an array of pointers to strings composed of dots and dashes)
// Done to preserve memory because strings are not equal in size. A 2D array
// would be a waste of space.
char *mCodes[] = {
//OTMK Codes
"-.-. --.- -.-. --.- -.-. --.- ", "--.- ... .-..", "callSign", "randNumber = random(1000001,99999)", "SK",
};
char *letters[] = {
// The letters A-Z in Morse code
".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..",
".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.",
"...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."
};
char *numbers[] = {
// The numbers 0-9 in Morse code
"-----", ".----", "..---", "...--", "....-", ".....", "-....",
"--...", "---..", "----."
};
unsigned int dot_duration = 75;
bool done = false;
/**
Function runs only once, after each powerup or reset of the Arduino
*/
void setup() {
pinMode(buttonPin, OUTPUT);
pinMode(led_pin, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(Pinone, INPUT_PULLUP);
pinMode(Pintwo, INPUT_PULLUP);
pinMode(Pinthr, INPUT_PULLUP);
pinMode(Pinfou, INPUT_PULLUP);
pinMode(Pinfiv, INPUT_PULLUP);
pinMode(Pinsix, INPUT_PULLUP);
digitalWrite(10, HIGH);
//these line just duplicate INPUT_PULLUP using alternative syntax
//digitalWrite(Pinone, HIGH);
//digitalWrite(Pintwo, HIGH);
//digitalWrite(Pinthr, HIGH);
//digitalWrite(Pinfou, HIGH);
//digitalWrite(Pinfiv, HIGH);
//digitalWrite(Pinsix, HIGH);
// Open the serial port and set the data transmission rate to 9600 bits
// per second. 9600 is the default baud rate for Arduino.
Serial.begin(9600);
// Show welcome message as human-readable ASCII text
Serial.println("OTMK Serial Logger Interface");
Serial.println("This program monitors your output codes");
Serial.println("controls the peizo buzzer and LED indicators");
Serial.println("Author: ONE TIME MORSE KEY");
Serial.println("");
Serial.println("While connected to serial, you can manually enter");
Serial.println("morse codes strings to transmit or '!' to exit the program which will require reboot ");
}
/**
Main function that drives the system
*/
void loop() {
char ch;
while (!done) {
if (digitalRead(Pinone) == LOW) {
//Serial.println(ch);
//flash_morse_code(mCodes[ch == "-.-. --.- -.-. --.- -.-. --.- "]);
Serial.println(mCodes[0]);
flash_morse_code(mCodes[0]);
Serial.println("Your transmision 'CQ CQ CQ'");
}
if (digitalRead(Pintwo) == LOW) {
//Serial.println(ch);
//flash_morse_code(mCodes[ch == ""]);
Serial.println(mCodes[1]);
flash_morse_code(mCodes[1]);
Serial.println("Your transmision 'QSL QSL'");
}
//its not clear which callsign you want to transmit
//char callSign[] = "Test Call Sign";
//mCode[2] = "callsign"
if (digitalRead(Pinthr) == LOW) {
//Serial.println(ch);
//flash_morse_code(mCodes[ch == ""]);
Serial.println(mCodes[2]);
flash_morse_code(mCodes[2]);
Serial.println("Your transmision");
Serial.println(callSign);
}
//random number transmission is not working correctly
if (digitalRead(Pinfou) == LOW) {
//Serial.println(ch);
//flash_morse_code(mCodes[ch == ""]);
Serial.println(mCodes[3]);
flash_morse_code(mCodes[3]);//should be random number
Serial.println("Your transmision");
Serial.println("OTMK ******");
}
if (digitalRead(Pinfiv) == LOW) {
digitalWrite(led_pin, HIGH);
tone(buzzer, 700);
}
if (digitalRead(Pinfiv) == HIGH)
digitalWrite(led_pin, LOW);
noTone(buzzer);
if (Serial.available()) {
// Read one letter or number at a time
// Serial.read() returns the first (oldest) character in the buffer
// and removes that byte of data from the buffer
ch = Serial.read();
// Check for uppercase letters
if (ch >= 'A' && ch <= 'Z') {
Serial.println(ch);
flash_morse_code(letters[ch - 'A']);
}
// Check for lowercase letters
else if (ch >= 'a' && ch <= 'z') {
Serial.println(ch);
flash_morse_code(letters[ch - 'a']);
}
// Check for numbers
else if (ch >= '0' && ch <= '9') {
Serial.println(ch);
flash_morse_code(numbers[ch - '0']);
}
// Check for space between words
else if (ch == ' ') {
// Put space between two words in a message...equal to seven dots
delay(dot_duration * 7);
}
// Check for sentinel value
else if (ch == '!') {
done = true;
Serial.println("Thank you! Your messages were sent successfully.");
Serial.println("Goodbye.");
}
}
}
// Do nothing
while (true) {}
}
/**
Flashes the Morse code for the input letter or number
@param morse_code pointer to the morse code
*/
void flash_morse_code(char *morse_code) {
unsigned int i = 0;
// Read the dots and dashes and flash accordingly
while (morse_code[i] != NULL) {
flash_dot_or_dash(morse_code[i]);
i++;
}
// Space between two letters is equal to three dots
delay(dot_duration * 3);
}
/**
Flashes the dot or dash in the Morse code
@param dot_or_dash character that is a dot or a dash
*/
void flash_dot_or_dash(char dot_or_dash) {
// Make the LED shine
digitalWrite(led_pin, HIGH);
tone(buzzer, 700);
if (dot_or_dash == '.') { // If it is a dot
delay(dot_duration);
}
else { // Has to be a dash...equal to three dots
delay(dot_duration * 3);
}
// Turn the LED off
digitalWrite(led_pin, LOW);
noTone(buzzer);
// Give space between parts of the same letter...equal to one dot
delay(dot_duration);
}