20
Code usage
“U8glib.h” is a library of OLED, it has very comprehensive usage methods and functions for you to call
and use OLED. So, first to includes the U8glib.h library into your program and then you can call the
function directly inside the library to using the OLED.
OLED Library: #include "U8glib.h"
Before you start using OLED, you need to initialize the OLED object. In fact, you need to tell which
type of OLED is used(SSD1306), what is the pixel(128X64), and what is the type of communication
between Arduino and OLED(U8G_I2C_OPT_NONE ). Therefore, your initialized OLED instance can
be used correctly by you.
Create instant object: U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);
We created a drawLogo() method to draw our logo and a drawURL() method to draw our URL. In
these two methods, we use the u8g.setFont() method to select the font we want to display and use
the u8g.drawStr() method to set what position and character we want to draw. There are three
parameters in the u8g.drawStr() function. The first parameter represents the abscissa position of the
character we need to draw, the second represents the ordinate position of the character to be drawn,
and the third represents the character to be drawn.
Draw text: void drawLogo(uint8_t d){//draw text you want} void drawURL(void)
{//draw text you want}
The drawing process must be performed in accordance with this framework, and the code displayed
by the drawing is executed in a loop composed of firstPage and nextPage.
Show the text you draw: u8g.firstPage();do{//put what you want to draw here} while
(u8g.nextPage()) ;
This HC-SR04 has stable performance and high ranging
accuracy. Compared to the Shap IR ranging module,
HC-SR04 is cheaper than it. But it has the same ranging
accuracy and longer ranging distance.
Lesson 9 – Ultrasonic ranging display
Introduction
Summary of Contents for Crowtail Deluxe Kit
Page 47: ......