SKETCH ARDUINO A.R.D.F.




// 2.11.2018, Arduino IDE v1.8.7, v0.2


// CW Beacon using Si5351, LZ2WSG, KN34PC


// MODIFICATO AD USO A.R.D.F. by IK1LBW ( giugno 2020)




#include "si5351.h"




#define PIN_SP 10 //monitor audio pin 10 arduino


#define PIN_TX 13 //led cw pin 13 arduino




Si5351 si5351(0x60);




uint16_t duration = 160;  //valore velocita' cw (80-100)(maggiore e' il valore...minore WPM)


uint16_t hz = 1750;  //valore nota monitor  al pin 10 di arduino


String cw_message = "T T T T";  //inserire il msg. da trasmettere (maiuscolo) settate una serie di < T >


uint32_t tx = 144100000;   // inserire freq. tx (es.)--> 144.444 mhz= 144444000 


//---------------------------------------------------------------------------------------------------------


void setup() {


  pinMode(PIN_TX, OUTPUT);




  si5351.init(SI5351_CRYSTAL_LOAD_8PF, 25000000, 0);


  si5351.set_freq(tx * SI5351_FREQ_MULT, SI5351_CLK1);


  si5351.output_enable(SI5351_CLK1, 0);


  si5351.drive_strength(SI5351_CLK1,SI5351_DRIVE_8MA); // variazione pwr out da 2 a 8 ma


}


//---------------------------------------------------------------------------------------------------------


void loop() {


  cw_string_proc(cw_message); // durata pausa tra msg. e portante fissa bcn (>1500)


  delay(2000);




  cw(true);


  delay(6000); // durata portante fissa tx a.r.d.f. (>5000)




  cw(false);


  delay(4000); // durata spazio tra portante fissa tx a.r.d.f. e inizio msg. (>3000)


}


//---------------------------------------------------------------------------------------------------------


void cw_string_proc(String str) {                      // processing string to characters


  for (uint8_t j = 0; j < str.length(); j++)


    cw_char_proc(str[j]);


}


//---------------------------------------------------------------------------------------------------------


void cw_char_proc(char m) {                            // processing characters to Morse code symbols


  String s;




  if (m == ' ') {                                      // пауза между думите


    word_space();


    return;


  }




  if (m > 96)                                          // ACSII, case change a-z to A-Z


    if (m < 123)


      m -= 32;




  switch (m) {                                    


  




    case 'T': s = "-#";      break;   // CODICE MORSE...LETTERA UTILIZZATA " T "


  


 


   


  }




  for (uint8_t i = 0; i < 7; i++) {


    switch (s[i]) {


      case '.': ti();  break;                          // TI (punto)


      case '-': ta();  break;                          // TA (linea)


      case '#': char_space(); return;                  // end of Morse code symbol


    }


  }


}


//---------------------------------------------------------------------------------------------------------


void ti() {


  cw(true);                                            // TX TI (punto)


  delay(duration);




  cw(false);                                           // stop TX TI (punto)


  delay(duration);


}


//---------------------------------------------------------------------------------------------------------


void ta() {


  cw(true);                                            // TX TA (linea)//valore modificato x allungare la nota.. originale = delay(3 * duration)


  delay(18 * duration);




  cw(false);                                           // stop TX TA (linea)


  delay(duration);


}


//---------------------------------------------------------------------------------------------------------


void char_space() {                                    // 3x, пауза между буквите


  delay(2 * duration);                                 // 1 from element-end + 2 new


}


//---------------------------------------------------------------------------------------------------------


void word_space() {                                    // 7x, пауза между думите


  delay(6 * duration);                                 // 1 from element-end + 6 new


}


//---------------------------------------------------------------------------------------------------------


void cw(bool state) {                                  // TX-CW, monitor>TX-LED, monitor audio> 3000 Hz sound


  if (state) {


    si5351.output_enable(SI5351_CLK1, 1);   // uscita r.f. su CLK1


    digitalWrite(PIN_TX, HIGH);


    tone(PIN_SP, hz);


  }


  else {


    si5351.output_enable(SI5351_CLK1, 0);


    digitalWrite(PIN_TX, LOW);


    noTone(PIN_SP);


  }


}