22 March 2010

Using Arduino software - user-defined functions (4) - a Morse Code flasher & buzzer

/*
* Project: functions_MorseCodeBuzzer
* Author: Jane-Maree Howard
* Date: Monday 22/03/2010
* Platform: Arduino 18
* Purpose: To demonstrate a Morse code buzzer.
* Operation: The buzzer makes only clicking noises so
* evidently we will have to make it oscillate,
* i.e. buzz. This will need its own routine call.
* I expect turning it on-off repeatedly will be enough.
* Most of the code has been re-used from MorseCode_MyName,
* since it does much the same thing, but with the exception
* of a buzzer routine call for every LED flash, since this
* what is associated with the sound.
*/

int pinBlu = 10; // off-board Blue LED
int pinBuzz = 12; // output to buzzer
int iBuzz = 12; // 'Buzz' oscillations cycle count
int i; // 'Buzz' oscillations counter
int dLay = iBuzz*3; // basic delay = 'dot' buzz cycle

void setup()
{
pinMode(pinBlu, OUTPUT);
pinMode(pinBuzz, OUTPUT);
digitalWrite(pinBlu, LOW);
digitalWrite(pinBuzz, LOW);
}//end setup()

/* This loop makes use of user-defined functions called dot() and dash()
which in turn make up the Morse letters e.g. Juliet()
Here I spell out my name: 'Jane-Maree Paula Howard'
*/
void loop()
{
delay(7*dLay); // 1.75 sec delay - delay between words
delay(7*dLay); // 1.75 sec delay - delay between words
delay(7*dLay); // 1.75 sec delay - delay between words
Juliet(); //J
Alpha(); //A
November(); //N
Echo(); //E
Hyphen(); //-
Mike(); //M
Alpha(); //A
Romeo(); //R
Echo(); //E
Echo(); //E
delay(7*dLay); // 1.75 sec delay - delay between words
Papa(); //P
Alpha(); //A
Uniform(); //U
Lima(); //L
Alpha(); //A
delay(7*dLay); // 1.75 sec delay - delay between words
Hotel(); //H
Oscar(); //O
Whiskey(); //W
Alpha(); //A
Romeo(); //R
Delta(); //D
delay(7*dLay); // 1.75 sec delay - delay between words
}//end loop() // Main body of program

/* Now we define the functions buzz(), dot() & dash()
These represent the 'character elements' of each alpha-numeric character.
Then we define the Alpha characters in terms of dot() & dash()
Note that buzz() is included in dot() & dash()
As can be seen above, calling these functions is quite easy.
*/

// buzz() is actually an oscillation routine; frequency ~500Hz
void buzz(int j)
{
for (i=0; i
{
delay(2);
digitalWrite(pinBuzz, HIGH);
delay(1);
digitalWrite(pinBuzz, LOW);
}//for(++)
}//end buzz()

void dot()
{
digitalWrite(pinBlu, HIGH);
buzz(iBuzz);
//delay(dLay); // 250 millisec delay - length of 'character element'
digitalWrite(pinBlu, LOW);
delay(2*dLay); // 500 millisec delay - delay between 'character elements'
}//end dot()

void dash()
{
digitalWrite(pinBlu, HIGH);
buzz(iBuzz*3);
//delay(dLay*3); // 750 millisec delay - length of 'character element'
digitalWrite(pinBlu, LOW);
delay(2*dLay); // 500 millisec delay - delay between 'character elements'
}//end dash()

/* Now we make functions using functions: in this case the Morse alphabet of
various characters; named using the military alpha-word-code - Alpha Bravo etc
*/
//Juliet di-dah-dah-dah
void Juliet()
{
dot();
dash();
dash();
dash();
delay(2*dLay);
}//end juliet()

//Alpha di-dah
void Alpha()
{
dot();
dash();
delay(2*dLay);
}//end Alpha()

//November dah-dit
void November()
{
dash();
dot();
delay(2*dLay);
}//end November()

//Echo dit
void Echo()
{
dot();
delay(2*dLay);
}//end Echo()

//Mike dah-dah
void Mike()
{
dash();
dash();
delay(2*dLay);
}//end Mike()

//Romeo di-dah-dit
void Romeo()
{
dot();
dash();
dot();
delay(2*dLay);
}//end Romeo()

//Hyphen dah-di-di-di-di-dah
void Hyphen()
{
dash();
dot();
dot();
dot();
dot();
dash();
delay(2*dLay);
}//end Hyphen()

//Papa di-dah-dah-dit
void Papa()
{
dot();
dash();
dash();
dot();
delay(2*dLay);
}//end Papa()

//Uniform di-di-dah
void Uniform()
{
dot();
dot();
dash();
delay(2*dLay);
}//end Uniform()

//Lima di-dah-di-dit
void Lima()
{
dot();
dash();
dot();
dot();
delay(2*dLay);
}//end Lima()

//Hotel di-di-di-dit
void Hotel()
{
dot();
dot();
dot();
dot();
delay(2*dLay);
}//end Hotel()

//Oscar dah-dah-dah
void Oscar()
{
dash();
dash();
dash();
delay(2*dLay);
}//end Oscar()

//Whiskey dah-dah-dah
void Whiskey()
{
dot();
dash();
dash();
delay(2*dLay);
}//end Whiskey()

//Delta dah-dit
void Delta()
{
dash();
dot();
dot();
delay(2*dLay);
}//end Delta()

/* end of user-defined functions */

1 comment: