SOS morse code in C programming 3. Objective The first lab is intended to famili
ID: 3747096 • Letter: S
Question
SOS morse code in C programming
3. Objective The first lab is intended to familiarize the student with the software development steps and to learn simple programming structure in C. In this lab you will write a program to blink an LED to send out an SOS Morse code. 4. System Requirements The designed system will blink an SOS Morse code message when a switch input is pressed. The Morse code message should be implemented as follows: .Blinking Morse code SOs (...___... ) DoT, DOT, DOT, DASH, DASH, DASH, DOT, DOT, DOT DOT is on for second and DASH is on for second, with % second between them. At the end of SOS, the program has a delay of 2 seconds before repeating. The message will continue to repeat as long as the switch is pressed. When the switch is released the LED should be offExplanation / Answer
Following is the executable code in c language for the given question
#include<stdio.h>
#include<time.h>
int dot,dash=0;//initially taking dot and dash as OFF
int LED=0;//initally taking lED input as OFF
//function to create delay in seconds, input should be given in milli seconds
void delay(int seconds)
{
// Converting time into milli_seconds
int milli_sec = 1000 * seconds;
// Stroing start time
clock_t start = clock();
// looping till required time is not acheived
while (clock() < start + milli_sec)
;
}
//function to create 3 dots, each at 1/4 second interval
void dotF(){
for (int i=0;i<3;i++){
dot=1;
printf(".");
delay(250);//dot will be on for 1/4 second which is 250 milli seonds
dot=0;
}
}
//function to create 2 dashes, each at 1/2 second interval
void dashF(){
for(int i=0;i<2;i++){
dash=1;
printf("_");
delay(500);//dot will be on for 1/4 second which is 250 milli seonds
dash=0;
}
}
int main()
{
while(1){//infinte loop to check LED switch status
scanf("%d",&LED);//reading input for LED. Enter 1 0r 0 to ON or OFF LED. Giving any other input will not show any result on the console screen
if(LED<2&&LED>-1){
if(LED==1){
dotF();
dashF();
dotF();
delay(2000);
}
}
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.