Video/TvThermometer/TvThermometer.ino
#include <TVout.h>
#include <fontALL.h>
#include "thermometer.h"
const float SUPPLY_VOLTAGE = 5.0;
const float MIN_TEMP = 5.5;
const float MAX_TEMP = 40.0;
const unsigned int SCREEN_WIDTH = 120;
const unsigned int SCREEN_HEIGHT = 96;
const unsigned int TEMP_SENSOR_PIN = A0;
const unsigned int SCALE_X_MIN = 8;
const unsigned int SCALE_Y_MIN = 6;
const unsigned int SCALE_Y_MAX = 75;
const unsigned int SCALE_WIDTH = 3;
const unsigned int SCALE_HEIGHT = SCALE_Y_MAX - SCALE_Y_MIN;
float current_temperature = 0.0;
unsigned long last_measurement = millis();
TVout TV;
At the beginning of our program, we include a few header files.
TVout.h
declares
TVout’s main class and all of its methods.
fontALL.h
contains the definition of
all fonts that TVout offers. If you don’t want to output any text, you don’t
have to include it. The
thermometer.h
file makes the graphical representation of
our thermometer available to our program. I’ll explain its content later.
After we’ve included all necessary header files, we define a few constants and
variables:
•
SUPPLY_VOLTAGE
defines the Arduino’s supply voltage, and
TEMP_SENSOR_PIN
contains the number of the pin to which you’ve connected the TMP36
sensor.
•
MIN_TEMP
and
MAX_TEMP
define the minimum and maximum temperatures
(in degrees Celsius) that the TV thermometer can display.
•
SCREEN_WIDTH
and
SCREEN_HEIGHT
define the screen’s width and height. Note
that the Arduino isn’t capable of displaying really big screen resolutions.
A width of 120 to 132 pixels and a height of 96 pixels is a reasonable
compromise.
•
SCALE_X_MIN
defines the minimum X position of the thermometer’s scale.
SCALE_Y_MIN
and
SCALE_Y_MAX
define the minimum and maximum Y positions
of the thermometer’s scale. We’ll need these constants to draw a rectangle
representing the current temperature later.
Chapter 8. Generating Video Signals with an Arduino • 136
report erratum • discuss
www.it-ebooks.info