0:24
everyone welcome to controllers tech
0:28
today in this video i will cover how to
0:31
create and use multiple page menu
0:33
with sd 7735 1.8 inch tft display
0:38
using stm32 of course
0:41
i will create three different pages and
0:43
control them using three buttons and
0:48
let's start by creating a project in
0:51
first i am using stm32f446re controller
0:58
give some name to the project and click
1:04
here is our cube mx first of all i am
1:08
setting the external crystal for the
1:20
now select the spi as the half duplex
1:24
to connect to the display here you can
1:27
see the clock and the mossy pins got
1:31
i still need to select some more pins
1:37
i am selecting pb6 for the cs pin
1:41
pa9 for the data or command and pc7 for
1:46
pin now in order to control the menu
1:50
we need to select three pins as the
1:52
external interrupt for the buttons
1:57
i will show the connection in a while
1:59
but let's do the clock setup first
2:03
i have 8 megahertz external crystal and
2:06
i want the system to run at maximum
2:13
now let's go back and set the spi clock
2:16
i am keeping it as 22 megahertz
2:22
now the spi setup is complete
2:26
let's set up the external interrupt pins
2:30
we need to enable the external
2:40
i will keep them pulled down and use the
2:43
falling edge as the trigger
2:45
this is because i am connecting the
2:47
buttons to the external 3 volt supply
2:50
and when i press the button the current
2:52
will sink into this pin
2:53
and the interrupt will be triggered when
3:08
here you can see the connection it's
3:11
better if you use an external 3 volt
3:14
because this is a less resistive path
3:16
compared to the display
3:18
and the more current syncs here so when
3:21
the display might flicker
3:31
this completes our setup here click save
3:34
to generate the project
3:44
first of all we need to include the
3:50
these are the same files from my
3:52
previous video about sd7735 display
3:56
and there is one new file that is tft
4:06
i have already covered how to connect
4:10
and you can watch the video on the top
4:18
you define your pins here
4:23
define the spi here and also the type of
4:26
display you are using
4:40
now let's see the tft menu.c file
4:54
this here is the home menu here we first
4:58
set the horizontal orientation
5:01
then fill the screen with black color
5:05
then we draw two buttons and then we set
5:08
the home menu variable
5:10
and reset the other variables
5:21
this is how it looks we have two buttons
5:25
and that is not the texture in the
5:26
background it's just the bad picture
5:47
to draw these buttons first i have drawn
5:49
the round rectangular white border
5:52
and then filled it with the red color
5:54
and then put a text in white color
6:02
when a button is selected we will change
6:04
the background to green
6:06
and the text color to black
6:12
i have defined the buttons here
6:21
and these are some variables to keep
6:23
track of what's being selected
6:35
in the test menu we set the test menu
6:45
then we perform all the tests on the
6:51
print this string and display the back
7:02
this is how it looks with the string and
7:13
then the page 2 menu will also set the
7:21
and display 3 buttons
7:32
you can see led on button led off button
7:44
now the external interrupts
7:56
when pa 0 is pressed enter will be set
7:59
and back and up will be reset
8:02
similarly when p a1 will be pressed
8:05
back button will be set and with pa4 up
8:08
button will be set and now comes the
8:13
menu handler this will basically handle
8:17
all the operations if we are inside the
8:21
and the down button is pressed then it
8:23
first checks if the test button is
8:25
already selected or not
8:31
if the test button is selected then it
8:34
will select the page 2 button
8:36
and unselect the test button also we
8:39
need to reset the down button or it will
8:43
in the menu again if the down button is
8:47
and if the page 2 button was already
8:49
selected the it will select the test
8:52
and unselect the page 2 button and if
8:55
the down button is pressed
8:57
but none of the two buttons were
8:58
selected then it will select the test
9:01
since it's the one the top in the menu
9:07
we use the same thing if the up button
9:11
check all the three conditions and
9:14
select the required buttons
9:16
now if the enter is pressed the again we
9:19
check if the test button is already
9:23
if it is then the test menu will be set
9:26
menu will be reset we also need to reset
9:30
the enter button to avoid any recursive
9:34
and if the enter is pressed and the page
9:36
2 button was selected
9:38
then the page 2 menu will be set
9:41
if none of the buttons were selected and
9:50
so we are done with home menu the test
9:53
and the page 2 menu also follows the
10:02
i will comment this code before posting
10:06
so you can have better idea of what each
10:10
let's go to the main file now
10:16
include the tft menu file first
10:20
we also need to include the sd 7735.h
10:24
for the initialization function
10:30
now in the main function initialize the
10:35
i will keep the rotation to zero here
10:38
fill the screen with black color and
10:41
now call the home menu here in the while
10:45
we will call the menu handler let's
10:52
seems like some warning here fill screen
10:56
is actually a function from the gfx
10:59
so we need to include that too or
11:02
instead i will just not include this
11:05
because home menu already have fill
11:07
screen function in the beginning
11:14
now everything is okay so let's upload
12:26
the display and the menu worked
12:30
this is it for this video you can
12:33
download the code from the link in the
12:37
keep watching and have a nice day ahead