Hardware Reference
In-Depth Information
B00000,
B00100,
B00100,
B00000,
B10001,
B01110,
};
Now, to attribute that data to a character, use createChar() :
lcd.createChar(num, data);
The num variable is the number of the character; slots 0 to 7 are available.
The data parameter is the data structure you created previously. For example:
lcd.createChar(0, smiley);
Finally, to use the custom character, use write() specifying the byte to use:
lcd.write(byte(num));
Example Program
For this example, you build a distance sensor: a small device that displays the
distance of the closest object to the device. Distance sensors are found in daily
life; for example, they are used on building sites to know the distance between
two walls or by real estate agents to calculate the size of a room. They are also
used by robots to detect obstacles and used by cars in exactly the same way to
help you reverse into a tight parking space.
There are several ways to achieve this, but they all rely on the same principle:
bouncing waves. By emitting a certain frequency, the device calculates the time
taken to receive a “copy” of that wave. Imagine yourself in a large open space:
a stadium or in the mountains. When you shout, you wait for a small period
of time before hearing your echo. Sound has traveled from your mouth and
propagates. When it hits a solid surface, it rel ects and is dispersed in different
directions. Some of that sound returns to you, and your ears hear the sound.
By calculating the time it took to hear your echo and factoring in the speed
of sound, you can get a rough estimate of the distance. However, this doesn't
work for small distances; the speed of sound is so fast that it is impossible for
a human to calculate the distances inside a house, but for electronics, it isn't a
problem. The HC-SR04 is one device that can do this.
The HC-SR04 is an ultrasonic distance sensor, as illustrated in Figure 11-3.
Ultrasonic distance sensors are easily recognizable by their shape. When placed
on a robot, it looks like two “eyes,” and in a way, they are. One “eye” is an
ultrasonic speaker, and the second is an ultrasonic microphone. Ultrasound
 
Search WWH ::




Custom Search