Next, we output the current temperature as text. We use TVout’s
select_font
,
set_cursor
, and
print
methods to output the text “Current Temperature” in a font
that is 6 pixels wide and 8 pixels high. After that, we output the current
temperature in degrees Celsius using the 8x8 font. The TVout library doesn’t
define a symbol for degrees Celsius, so we use the
draw_circle
method in line
21 to draw a small circle to simulate a degrees symbol.
We’re done! That’s all the code we need to make the TV thermometer work.
The only thing I haven’t explained in detail is how outputting the thermometer
image works. You’ll learn more about that in the next section.
Working with Graphics in TVout
In
TvThermometer.ino
we’ve included the
thermometer.h
file without explaining what
it contains. Here’s how it looks:
Video/TvThermometer/thermometer.h
#ifndef THERMOMETER_H
#define THERMOMETER_H
extern const unsigned char thermometer[];
#endif
Quite disappointing, isn’t it? The file declares only a single variable named
thermometer
. This variable is an array of unsigned character values, and the
extern
keyword tells the compiler that we only want to declare the variable.
That is, we can refer to it in our program, but we still have to define it to
allocate some memory.
We actually define the
thermometer
variable in
thermometer.cpp
(we’ve skipped a
few lines for brevity):
Video/TvThermometer/thermometer.cpp
#include <Arduino.h>
Line 1
#include <avr/pgmspace.h>
-
#include "thermometer.h"
-
PROGMEM const unsigned char thermometer[] = {
-
20, 94,
5
B00000000, B11110000, B00000000,
-
B00000001, B00001000, B00000000,
-
B00000010, B00000100, B00000000,
-
B00000010, B00000100, B00000000,
-
B00000010, B00000100, B00000000,
10
B00000010, B00000111, B10000000, // 40.0
-
B00000010, B00000100, B00000000,
-
B00000010, B00000100, B00000000,
-
B00000010, B00000100, B00000000,
-
B00000010, B00000100, B00000000,
15
B00000010, B00000100, B00000000,
-
report erratum • discuss
Working with Graphics in TVout • 139
www.it-ebooks.info