ROLLBOTMICRO
29
}
/*********OLED data writing***********/
void
RollbotOLED
::
WriteData
(
unsigned
int
dat
)
{
Wire
.
beginTransmission
(
0x78
>>
1
);
//0x78 >> 1
Wire
.
write
(
0x40
);
//0x40
Wire
.
write
(
dat
);
Wire
.
endTransmission
();
}
Next, the function for positions on the OLED screen:
SetPos()
. With this function, you can locate
the specific point of the OLED display.
void
RollbotOLED
::
IIC_SetPos
(
unsigned
int
x
,
unsigned
int
y
)
{
WriteCommand
(
0xb0
+
y
);
WriteCommand
(((
x
&
0xf0
)
>>
4
)
|
0x10
);
//|0x10
WriteCommand
((
x
&
0x0f
)
|
0x00
);
//|0x01
}
Apart from the three basic functions, you can use more for display on the OLED screen. The
current code is adequate for displaying sensor signal intensity easily. For more information, you
can refer to the program
RollbotOLED.CPP
in the library.
7.3 Line Following
The line following function is the most important function of the robot. It distinguishes the black
and white surfaces through the infrared sensor module and applies the PD algorithm to realize
line following. It collects and saves the AD value of the 5 pins: A0, A1, A2, A3, and A7.
SunFounder