среда, 30 марта 2016 г.

Arduino CW Beacon

Простой arduino CW Beacom и одноплатный трансивер QRP Pixie CW Kit on 7.023 MHz
сразу приведу скетч
Pin4 - PTT
Pin13 - CW
Pin5 - Speaker






// Simple CW Beacon

int pinPTT = 4;
int MorseLEDPin = 13;
int MorseTonePin = 5;
int MorseToneFreq = 700;
int MorseWPM = 16;

// Declare variables...
#define strBeacondID "CQ CQ CQ DE RL5D RL5D PSE K"

// Bung Morse into an array
char* MorseCodeCharacters[] = {
"A", ".-", 
"B","-...", 
"C","-.-.", 
"D","-..", 
"E",".", 
"F","..-.", 
"G","--.", 
"H","....", 
"I","..", 
"J",".---", 
"K","-.-", 
"L",".-..", 
"M","--", 
"N","-.", 
"O","---", 
"P",".--.", 
"Q","--.-", 
"R",".-.", 
"S","...", 
"T","-", 
"U","..-", 
"V","...-", 
"W",".--", 
"X","-..-", 
"Y","-.--",
"Z","--..",
"0","-----", 
"1",".----", 
"2","..---",
"3","...--",
"4","....-",
"5",".....",
"6","-....",
"7","--...",
"8","---..",
"9","----.",
"/","-..-.",
"*","-.-.-",
".",".-.-.",
"&","...-.-",
" "," "
};
  
// ----------------------------------------------------------------------------------------


void setup() {
  Serial.begin(9600);
  pinMode(pinPTT, OUTPUT);
  pinMode(MorseLEDPin, OUTPUT);
  pinMode(MorseTonePin, OUTPUT);
  Serial.println("RL5D CW Beacon - Welcome"); Serial.println(); 
}

  void TransmitMorse(String MorseString, int MorseWPM,int MorseToneFreq) {
  
  Serial.print("Message: ");
  Serial.println(MorseString);
  
  int CWdot = 1200 / MorseWPM;
  int CWdash = (1200 / MorseWPM)*3;
  int istr;
  for (istr=0; istr < MorseString.length(); istr++) {
    String currentchar = MorseString.substring(istr,istr+1);
    int ichar = 0;
    while(ichar < sizeof(MorseCodeCharacters)) {
      String currentletter = MorseCodeCharacters[ichar];   // letter
      String currentcode = MorseCodeCharacters[ichar+1];   // corresponding morse code
      if (currentletter.equalsIgnoreCase(currentchar)) {
        int icp=0;
        for (icp=0;icp < currentcode.length(); icp++) {
          // Transmit Dit
          if (currentcode.substring(icp,icp+1).equalsIgnoreCase(".")) { 
            digitalWrite(MorseLEDPin, HIGH);
            tone(MorseTonePin, MorseToneFreq);
            delay(CWdot);
            digitalWrite(MorseLEDPin, LOW);
            noTone(MorseTonePin);
            delay(CWdot);
          }
          // Transmit Dah
          else if (currentcode.substring(icp,icp+1).equalsIgnoreCase("-")) {
            digitalWrite(MorseLEDPin, HIGH);
            tone(MorseTonePin, MorseToneFreq);
            delay(CWdash);
            digitalWrite(MorseLEDPin, LOW);
            noTone(MorseTonePin);
            delay(CWdot); 
          }
          else if (currentcode.substring(icp,icp+1).equalsIgnoreCase(" ")) {
            delay(CWdot*3);
          };
          }
        }
        ichar=ichar+2;
     }
      delay(CWdot*3);
      }    
    delay(CWdot*7);
  }

void loop() {
  digitalWrite(pinPTT, HIGH);
  TransmitMorse(strBeacondID, MorseWPM, MorseToneFreq); 
  digitalWrite(pinPTT, LOW);
  delay(5000);
}

Комментариев нет:

Отправить комментарий