/*
Baudot (ITA2) Demonstration
Arduino Uno R3
Piezo Buzzer:
+ -> Pin 8
- -> GND
Serial Monitor: 9600 baud
*/
const int BUZZER = 8;
struct BaudotEntry {
char letter;
byte code;
};
// ITA2 LETTERS SHIFT TABLE
BaudotEntry baudotTable[] = {
{'A', 0b00011},
{'B', 0b11001},
{'C', 0b01110},
{'D', 0b01001},
{'E', 0b00001},
{'F', 0b01101},
{'G', 0b11010},
{'H', 0b10100},
{'I', 0b00110},
{'J', 0b01011},
{'K', 0b01111},
{'L', 0b10010},
{'M', 0b11100},
{'N', 0b01100},
{'O', 0b11000},
{'P', 0b10110},
{'Q', 0b10111},
{'R', 0b01010},
{'S', 0b00101},
{'T', 0b10000},
{'U', 0b00111},
{'V', 0b11110},
{'W', 0b10011},
{'X', 0b11101},
{'Y', 0b10101},
{'Z', 0b10001}
};
void setup() {
Serial.begin(9600);
Serial.println("Baudot (ITA2) Demonstration");
Serial.println("--------------------------");
sendMessage("HELLO");
}
void loop() {
delay(5000);
}
byte getBaudot(char c) {
c = toupper(c);
for (unsigned int i = 0; i < sizeof(baudotTable)/sizeof(baudotTable[0]); i++) {
if (baudotTable[i].letter == c) {
return baudotTable[i].code;
}
}
return 0;
}
void sendBit(bool bitValue) {
if (bitValue) {
tone(BUZZER, 1200); // Logic 1
} else {
tone(BUZZER, 500); // Logic 0
}
delay(150);
noTone(BUZZER);
delay(50);
}
void sendCharacter(char c) {
byte code = getBaudot(c);
Serial.print(c);
Serial.print(" = ");
// Print as 5-bit binary
for (int bit = 4; bit >= 0; bit--) {
Serial.print((code >> bit) & 1);
}
Serial.println();
// Send bits MSB first
for (int bit = 4; bit >= 0; bit--) {
sendBit((code >> bit) & 1);
}
delay(300);
}
void sendMessage(const char *msg) {
Serial.print("Message: ");
Serial.println(msg);
Serial.println();
while (*msg) {
if (*msg >= 'A' && *msg <= 'Z') {
sendCharacter(*msg);
}
msg++;
}
}