Page 102 - ARM Based Microcontroller Projects Using MBED
P. 102
88 7. USING THE Mbed WITH SIMPLE PROJECTS
*******************************************************************
LED FLASHING SOS MORSE CODE
===========================
In this program the user LED flashes as an SOS Morse code.
The SOS Morse code is "...---...". Here, a dot is represented
with the LED being ON for 0.25 seconds (Dot time)and a dash is
represented with the LED being ON for 1 second (Dash time. The
delay between the dots and dashes is set to 0.2 second (GAP time).
The process is repeated continuously after 2 seconds of delay
Author: Dogan Ibrahim
Date : August 2018
File : sos
********************************************************************/
#include "mbed.h"
DigitalOut LED(LED1);
#define Dot 0.25 // Dot time
#define Dash 1.0 // Dash time
#define Gap 0.2 // Gap time
#define ON 1 // ON=1
#define OFF 0 // OFF=0
int main()
{
int i;
while(1) // Do Forever
{
for(i = 0; i < 3; i++) // Send 3 dots
{
LED = ON; // LED ON
wait(Dot); // Wait Dot time
LED = OFF; // LED OFF
wait(Gap); // Wait Gap time
}
wait(0.5); // 0.5 second delay
for(i = 0; i < 3; i++) // Send 3 dashes
{
LED = ON; // LED ON
wait(Dash); // Wait Dash time
LED = OFF; // LED OFF
wait(Gap); // Wait GAp time
}
wait(2.0); // Wait 2 second before repeating
}
}
FIG. 7.17 Program listing.