Programming Arduino Getting Started with Sketches


float of (for example) 20.25 to an  int



Yüklə 5,42 Kb.
Pdf görüntüsü
səhifə63/78
tarix22.12.2023
ölçüsü5,42 Kb.
#189286
1   ...   59   60   61   62   63   64   65   66   ...   78
Arduino SimonMonk 2011

float
of (for example) 20.25 to an 
int
that will simply
truncate the number to 20.
If you know that the highest temperature that you care about is 60 degrees Celsius and
that the lowest is 0 degrees Celsius, then you could multiply every temperature by 4
before converting it to a byte and saving it. Then when you read the data back from
EEPROM, you can divide by 4 to get a value that has a precision of 0.25 of a degree.
The following code example (sketch 8-04) saves such a temperature into EEPROM,
then reads it back and displays it in the Serial Monitor as proof:
There are other means of compressing data. For instance, if you are taking readings that
change slowly—again, changes in temperature are a good example of this—then you can
record the first temperature at full resolution and then just record the changes in
temperature from the previous reading. This change will generally be small and occupy
fewer bytes.
Conclusion
You now know a little about how to make your data hang around after the power has gone
off. In the next chapter, you will look at LCD displays.



9
LCD Displays
In this
chapter, you look at how to write software to control LCD displays. 
Figure 9-1
shows the kind of LCD display used.
This is a book about software, not hardware, but in this chapter, we will have to explain
a little about how the electronics of these displays work so that you understand how to
drive them.
The LCD module that we use is a prebuilt Arduino shield that can just be plugged on
top of an Arduino board. In addition to its display, it also has some buttons. There are a
number of different shields, but nearly all of them use the same LCD controller chip (the
HD44780), so look for a shield that uses this controller chip.
I used the DFRobot LCD Keypad Shield for Arduino. This module supplied by
DFRobot (
www.robotshop.com
) is inexpensive and provides an LCD display that is 16
characters by 2 rows and also has six pushbuttons.
The shield comes assembled, so no soldering is required; you just plug it on top of your
Arduino board (see 
Figure 9-2
).
The LCD shield uses seven of the Arduino pins to control the LCD display and one
analog pin for the buttons. So we cannot use these Arduino pins for any other purpose.

Yüklə 5,42 Kb.

Dostları ilə paylaş:
1   ...   59   60   61   62   63   64   65   66   ...   78




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin