Advertisement
yo9gjx

A.R.D.F. Fox hunting Arduino UNO

Mar 25th, 2025
518
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | Sports | 0 0
  1. const int relayPin = 2;
  2. const int audioPin = 3;
  3. const int dotDuration = 130; // Durata punctului în milisecunde
  4. const int dashDuration = 3 * dotDuration;
  5.  
  6. void setup() {
  7.   pinMode(relayPin, OUTPUT);
  8.   pinMode(audioPin, OUTPUT);
  9. }
  10.  
  11. void loop() {
  12.   String cuvinte[] = {"MOE", "MOI", "MOS", "MOH", "MO5"};
  13.  
  14.   for (int i = 0; i < 5; i++) {                   // Parcurge fiecare cuvânt
  15.     for (int j = 0; j < 15; j++) {                // Repetă de 15 ori
  16.       transmiteMorse(cuvinte[i]);                 // Transmite cuvântul
  17.     }
  18.   }
  19.  
  20.   delay(5000); // Pauză de 5 secunde după fiecare ciclu complet
  21. }
  22.  
  23. void transmiteMorse(String cuvant) {
  24.   for (int i = 0; i < cuvant.length(); i++) {
  25.     char litera = cuvant.charAt(i);
  26.     simbolMorse(litera);
  27.    
  28.     // Spațiu între litere (3 unități)
  29.     if (i < cuvant.length() - 1) {
  30.       delay(3 * dotDuration);
  31.     }
  32.   }
  33.   // Spațiu între cuvinte (7 unități)
  34.   delay(7 * dotDuration);
  35. }
  36.  
  37. void simbolMorse(char caracter) {
  38.   String cod;
  39.   switch (caracter) {
  40.     case 'M': cod = "--"; break;
  41.     case 'O': cod = "---"; break;
  42.     case 'E': cod = "."; break;
  43.     case 'I': cod = ".."; break;
  44.     case 'S': cod = "..."; break;
  45.     case 'H': cod = "...."; break;
  46.     case '5': cod = "....."; break;
  47.     default: return;
  48.   }
  49.  
  50.   for (int i = 0; i < cod.length(); i++) {
  51.     digitalWrite(relayPin, HIGH);
  52.     tone(audioPin, 1000); // Generează ton de 1000Hz
  53.    
  54.     if (cod[i] == '.') {
  55.       delay(dotDuration);
  56.     } else {
  57.       delay(dashDuration);
  58.     }
  59.    
  60.     digitalWrite(relayPin, LOW);
  61.     noTone(audioPin);
  62.    
  63.     // Spațiu între simboluri (1 unitate)
  64.     if (i < cod.length() - 1) delay(dotDuration);
  65.   }
  66. }
  67.  
Advertisement
Comments
  • yo9gjx
    15 hours
    # text 0.39 KB | 0 0
    1. Code for basic training in Radio Orienteering sport, Fox hunting, for ARDUINO UNO transmitting basic morse MOE, MOI, MOS, MOH, MO5. with 2 exits: Pin 3 speaker with 1000 Hz tone and Pin 2 relay output for TX keying.
    2. Every fox is sent 15 times, after that the code moves to the next fox. At the end is a 5 seconds pause then the cycle start again.
    3. The dotDuration can be adjusted to change the speed.
Add Comment
Please, Sign In to add comment
Advertisement