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

Programming-Arduino (1) - Pages-104

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)
7 views1 page

Programming-Arduino (1) - Pages-104

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

}

At first, this might seem a bit strange. You are using <= and >= to compare
characters. You can do that because each character is actually represented by a
number (its ASCII code). So, if the code for the character is somewhere between
a and z (97 and 122), then you know that the character that has come from the
computer is a lowercase letter. You then call a function that you have not written
yet called flashSequence , to which you will pass a string of dots and dashes; for
example, to flash a , you would pass it .- as its argument.
You are devolving responsibility to this function for actually doing the
flashing. You are not trying to do it inside the loop . This lets us keep the code
easy to read.
Here is the C that determines the string of dashes and dots that you need to
send to the flashSequence function:
letters[ch - 'a']

Once again, this looks a little strange. The function appears to be subtracting
one character from another. This is actually a perfectly reasonable thing to do,
because the function is actually subtracting the ASCII values.
Remember that you are storing the codes for the letters in an array. So the
first element of the array contains a string of dashes and dots for the letter A , the
second element includes the dots and dashes for B , and so on. So you need to
find the right position in the array for the letter that you have just fetched from
the buffer. The position for any lowercase letter will be the character code for the
letter minus the character code for a . So, for example, a − a is actually 97 − 97
= 0. Similarly, c − a is actually 99 − 97 = 2. So, in the following statement, if ch
is the letter c, then the bit inside the square brackets would evaluate to 2, and you
would get element 2 from the array, which is -.-:
What this section has just described is concerned with lowercase letters. You
also have to deal with uppercase letters and numbers. These are both handled in
a similar manner.

The flashSequence Function


We have assumed a function called flashSequence and made use of it, but now

You might also like