0% found this document useful (0 votes)
14 views1 page

Programming-Arduino (1) - Pages-105

Uploaded by

axl1994
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
14 views1 page

Programming-Arduino (1) - Pages-105

Uploaded by

axl1994
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 1

you need to write it.

We have planned for it to take a string containing a series of


dashes and dots and to make the necessary flashes with the correct timings.
Thinking about the algorithm for doing this, you can break it into the
following steps:
♦ For each element of the string of dashes and dots (such as .-.-):
♦ Flash that dot or dash.
Using the concept of programming by intention, let’s keep the function as
simple as that.
The Morse codes are not the same length for all letters, so you need to loop
around the string until you encounter the end marker, \ 0. You also need a
counter variable called i that starts at 0 and is incremented as the processing
looks at each dot and dash:
void flashSequence(char* sequence)

int i = 0;

while (sequence[i] != '\0')

flashDotOrDash(sequence[i]);

i++;

delay(dotDelay * 3); // gap between letters

Again, you delegate the actual job of flashing an individual dot or dash to a
new method called flashDotOrDash , which actually turns the LED on and off.

You might also like