Telegraph - Morse encoder/decoder

Hello,

I would like to make a kind of telegraph using a buzzer plugged into my arduino card, and sending morse code to my PC, which will decode it and show alphanumerics caracters.

I have an "arduino" card provided by my University, which is actually not a real Arduino card, but it basically does exactly the same things. I started to write code, but it does not work, nothing happens when I press the buzzer.

Could anyone help me please?

Yes.
Hello arduinouca
Post your current sketch, well formated, with comments and in so called code tags "</>" and a schematic, not a Fritzy diagram, to see how we can help.
Have a nice day and enjoy coding in C++.
Дайте миру шанс

Buzzers are devices that make a noise. They are not devices that react on a press.

Arduino has Morse examples:
https://www.arduino.cc/reference/en/libraries/morse/

Here is one example: Problem in order of execution of functions however, the decoding is done on an Arduino, not on a PC.

Thank you all for your fast answers. I'm novice in both programming and making such projects.

Here is picture of my arduino card, with a press button included (the button I am supposed to press to make morse code) :

At the moment, I didnt not connect any buzzer to the card, but I am supposing the push button alone should make the whole system work?

Here is the code I used . I did not write it myself, but I've checked it and it seems correct:

const int letterPin = 6; //you can change these two pins to whatever you want
const int spacePin = 0;

unsigned long startPressedLetter;
unsigned long endPressedLetter;
unsigned long timeHeldLetter;
int buttonStateLetter = 0;
int lastButtonStateLetter = 0;

const unsigned long cutoff = 300; //I find that 300 ms works best
String morseLetter = "";

void setup() {
  Serial.begin(9600);
  pinMode(letterPin, INPUT);
  pinMode(spacePin, OUTPUT);
}

void loop() {
  //all about the letter button
  buttonStateLetter = digitalRead(letterPin); //Did the letter button state change?
  if (buttonStateLetter != lastButtonStateLetter) { //if button is pressed or released:
    if (buttonStateLetter == HIGH) { //if it was pressed
      startPressedLetter = millis(); //save the time when it was pressed
    } else { //if it was released
      endPressedLetter = millis(); //save the time it was released
      timeHeldLetter = endPressedLetter - startPressedLetter; //calculate how long it was held down for
      morseLetter += isDash(timeHeldLetter); //this will be the morse code for a single letter
      delay(50);
      Serial.println(morseLetter);
    }
  }
  lastButtonStateLetter = buttonStateLetter; //the current button state is now the old one too;
  //other buttons
  checkSpace();
}

void checkSpace(){
  if (digitalRead(spacePin) == HIGH) { //if space button pressed down
    delay(500);
    morseLetter = "";
  }
}

char determineLetter() {
  if (morseLetter == "01") {
    return 'A';
  } else if (morseLetter == "1000") {
    return 'B';
  } else if (morseLetter == "1010") {
    return 'C';
  } else if (morseLetter == "100") {
    return 'D';
  } else if (morseLetter == "0") {
    return 'E';
  } else if (morseLetter == "0010") {
    return 'F';
  } else if (morseLetter == "110") {
    return 'G';
  } else if (morseLetter == "0000") {
    return 'H';
  } else if (morseLetter == "00") {
    return 'I';
  } else if (morseLetter == "0111") {
    return 'J';
  } else if (morseLetter == "101") {
    return 'K';
  } else if (morseLetter == "0100") {
    return 'L';
  } else if (morseLetter == "11") {
    return 'M';
  } else if (morseLetter == "10") {
    return 'N';
  } else if (morseLetter == "111") {
    return 'O';
  } else if (morseLetter == "0110") {
    return 'P';
  } else if (morseLetter == "1101") {
    return 'Q';
  } else if (morseLetter == "010") {
    return 'R';
  } else if (morseLetter == "000") {
    return 'S';
  } else if (morseLetter == "1") {
    return 'T';
  } else if (morseLetter == "001") {
    return 'U';
  } else if (morseLetter == "0001") {
    return 'V';
  } else if (morseLetter == "011") {
    return 'W';
  } else if (morseLetter == "1001") {
    return 'X';
  } else if (morseLetter == "1011") {
    return 'Y';
  } else if (morseLetter == "1100") {
    return 'Z';
  } else if (morseLetter == "") {
    return ' ';
  } else if (morseLetter == "010101") {
    return '.';
  } else if (morseLetter == "110011") {
    return ',';
  } else if (morseLetter == "001100") {
    return '?';
  } else if (morseLetter == "10010") {
    return '/';
  } else if (morseLetter == "011010") {
    return '@';
  } else if (morseLetter == "01111") {
    return '1';
  } else if (morseLetter == "00111") {
    return '2';
  } else if (morseLetter == "00011") {
    return '3';
  } else if (morseLetter == "00001") {
    return '4';
  } else if (morseLetter == "00000") {
    return '5';
  } else if (morseLetter == "10000") {
    return '6';
  } else if (morseLetter == "11000") {
    return '7';
  } else if (morseLetter == "11100") {
    return '8';
  } else if (morseLetter == "11110") {
    return '9';
  } else if (morseLetter == "11111") {
    return '0';
  } else {
    Serial.println("That's not Morse.");
  }
}

boolean isDash(long input) { //true means dash, false means dot
  if (input < cutoff) {
    return false;
  } if (input >= cutoff) {
    return true;
  }
}

You would not want to confess to that insult to a telegraphist! :astonished: :rofl: