Hardware Reference
In-Depth Information
Again, it prints out some default text and then prints another variable, its own
name. Finally, it prints out the new line character. These four lines of code are
printed on a single line of text.
On line 27, the sketch again asks the user a question, and on line 32, it waits
for another 10 seconds for the user to enter some text. On line 33, the sketch
calls parseInt() , emptying the buffer looking for numbers. The result is stored
in the age variable.
On line 36, the sketch again talks to the user, i rst coni rming her age, and
then on line 40 calls millis() . This function returns the number of milliseconds
that the sketch has been running.
At line 43, the sketch prints out a formatted table, using tabs. The sketch tells
the user that it knows its ABCs, and demonstrates its mastery of the alphabet.
The i rst column will be the letter, the second will be the decimal value, and
the third will be the hexadecimal value.
Line 46 is a loop that iterates through letters A to Z. These are chars and can
be printed as such. In ASCII, capital letters are associated with values from
65 to 90. write() sends these as bytes. The Arduino's serial monitor interprets
these as the ASCII equivalent. If print() had been used, the decimal number
would have been printed, as on line 50. On line 52, the sketch again prints the
value but this time using hexadecimal notation.
The result of the sketch looks like this:
Hello! What is your name?
> Elena
Hello, Elena. My name is Arduino
How old are you, Elena?
> I am 8 years old.
Oh, you are 8?
I am 21001 microseconds old. Well, my sketch is.
I know my alphabet! Let me show you!
Letter Dec Hex
A 65 41
B 66 42
C 67 43
D 68 44
E 69 45
F 70 46
G 71 47
H 72 48
I 73 49
J 74 4A
K 75 4B
L 76 4C
M 77 4D
Search WWH ::




Custom Search