Hello experts,
I need some clarifications on how to use the custom made void functions.
This is a simple CW beacon, for the non "ham radio speaking" folks it's a circuit that is keying a transmitter on/off to send a string in Morse code.
So, this is my approach:
First I define the basic characters, the dot and the dash (di and dah) and all the different variables that are required to have the correct spacing between characters of the same letter, characters of the same word, two consecutive words.
My idea is to create a void function for dot and a void function for dash, and then combine them to define each letter,number,special character...
Then I would simply place the functions in loop,character after character,to compose the words I want to transmit.
For testing purpose, I've just defined 3 void functions:
dot
dash
letter V
Once I prove the concept is working, I'll add all the remaining letters and numbers.
I've been doing some reading on void functions, and found out that they were placed in different locations, sometimes after the end of loop, sometimes after the end of setup.
I'm getting confused now, I would like to understand where is the right place to put them.
Once more thing:
The void function defining the letter V (the same will apply to any other letter/number) is calling the other 2 void functions di(dot) and da(dash), is it going to work like this?
In other words:
since each character will be using a combination of the 2 main void functions dot and dash, is it ok to create a void function that has embedded void functions (recalls other void functions)?
Any chances the attached code will work?
Thanks
int Buz = A3;//
int Led = 6; //
int PotSpeed = A0;//
int PotFreq = A1;//
int Freq = 850;//
int Dit = 0 ;//
int Dah = 0 ; //
int InterLetter = 0 ;//
int BetweenLetters = 0 ; //
int BetweenWords = 0 ; //
void setup()
{
pinMode(Led, OUTPUT);
Serial.begin(1200);
}
void di() //
{
tone(Buz, Freq); //
digitalWrite(Led, HIGH);//
delay(Dit);//
noTone(Buz);//
digitalWrite(Led, LOW); //
delay(InterLetter);
}
void da() //
{
tone(Buz, Freq); //
digitalWrite(Led, HIGH);//
delay(Dah);//
noTone(Buz);//
digitalWrite(Led, LOW); //
delay(InterLetter);
}
void V()// di di di da (...-)
{
di();
delay(InterLetter);
di();
delay(InterLetter);
di();
delay(InterLetter);
da();
delay(BetweenLetters);
}
void loop()
{
int Freq = map(analogRead(PotFreq), 0, 1023, 30, 4999); //
int Dit = map(analogRead(PotSpeed), 0, 1023, 50, 150); //
int Dah = 3 * Dit ; //
int InterLetter = Dit ;//
int BetweenLetters = 3 * Dit ; //
int BetweenWords = 4 * Dit ; //
{
void V();
void V();
void V();
}
Serial.print("Freq="); //
Serial.print(Freq); //
Serial.print(" "); //
Serial.println(); //
Serial.print("Dit="); //
Serial.print(Dit); //
Serial.print(" "); //
Serial.print(" Dah(3dit)="); //
Serial.print(Dah); //
Serial.print(" "); //
Serial.println(); //
Serial.print("InterLetter(dit)="); //
Serial.print(InterLetter); //
Serial.print(" "); //
Serial.print(" BetweenLetters(3dit)="); //
Serial.print(BetweenLetters); //
Serial.print(" "); //
Serial.print(" BetweenWords(4dit)="); //
Serial.print(BetweenWords); //
Serial.print(" "); //
Serial.println(); //
Serial.println(); //
}