@@ -14,15 +14,14 @@ LVGL is a very powerful graphical framework that is compatible with the GIGA Dis
14
14
- [ Arduino GIGA R1 WiFi] ( /hardware/giga-r1 )
15
15
- [ Arduino GIGA Display Shield] ( /hardware/giga-display-shield )
16
16
- [ Arduino IDE] ( https://www.arduino.cc/en/software )
17
- - [ Arduino_H7_Video] ( https://github.com/arduino/ArduinoCore-mbed/tree/main/libraries/Arduino_H7_Video ) library
18
17
- [ Arduino_GigaDisplayTouch] ( https://github.com/arduino-libraries/Arduino_GigaDisplayTouch ) library
19
18
20
19
## Downloading the Library and Core
21
20
22
21
The GIGA core includes a library that will help us handle the display, so make sure you have the latest version of the core.
23
22
24
23
In this guide, we will be using three different libraries:
25
- - ** Arduino_H7_Video** , this one is bundled with the core, so make sure you have the latest version of the [ Mbed core] ( https://github.com/arduino/ArduinoCore-mbed )
24
+ - ** [ Arduino_H7_Video] ( https://github.com/arduino/ArduinoCore-mbed/tree/main/libraries/Arduino_H7_Video ) ** , this one is bundled with the core, so make sure you have the latest version of the [ Mbed core] ( https://github.com/arduino/ArduinoCore-mbed )
26
25
- ** Arduino_GigaDisplayTouch**
27
26
- ** lvgl**
28
27
@@ -150,6 +149,52 @@ To make sure we see the image use the align function to make it centered. Then a
150
149
151
150
![ An image rendered on the Display Shield with LVGL] ( assets/image.svg )
152
151
152
+ ### Full Example
153
+
154
+ ``` arduino
155
+ #include "Arduino_H7_Video.h"
156
+ #include "lvgl.h"
157
+
158
+ Arduino_H7_Video Display(800, 480, GigaDisplayShield);
159
+
160
+ void setup() {
161
+ Display.begin();
162
+
163
+ lv_obj_t * screen = lv_obj_create(lv_scr_act());
164
+ lv_obj_set_size(screen, Display.width(), Display.height());
165
+
166
+ static lv_coord_t col_dsc[] = { 500, LV_GRID_TEMPLATE_LAST};
167
+ static lv_coord_t row_dsc[] = { 400, LV_GRID_TEMPLATE_LAST};
168
+
169
+ lv_obj_t * grid = lv_obj_create(lv_scr_act());
170
+
171
+ lv_obj_set_grid_dsc_array(grid, col_dsc, row_dsc);
172
+
173
+ lv_obj_set_size(grid, Display.width(), Display.height());
174
+
175
+ lv_obj_center(grid);
176
+
177
+ lv_obj_t * obj;
178
+ lv_obj_t * img1;
179
+
180
+ obj = lv_obj_create(grid);
181
+ lv_obj_set_grid_cell(obj, LV_GRID_ALIGN_STRETCH, 0, 1,
182
+ LV_GRID_ALIGN_STRETCH, 0, 1);
183
+
184
+ LV_IMG_DECLARE(img_arduinologo);
185
+
186
+ img1 = lv_img_create(obj);
187
+ lv_img_set_src(img1, &img_arduinologo);
188
+
189
+ lv_obj_align(img1, LV_ALIGN_CENTER, 0, 0);
190
+ lv_obj_set_size(img1, 200, 150);
191
+ }
192
+
193
+ void loop() {
194
+ lv_timer_handler();
195
+ }
196
+ ```
197
+
153
198
## Functional Elements
154
199
155
200
### Checkbox
@@ -177,6 +222,56 @@ The startup state of the checkbox can be set with `lv_obj_add_state()`. Where th
177
222
178
223
![ Checkboxes rendered on the Display Shield with LVGL] ( assets/checkboxes.svg )
179
224
225
+ ### Full Example
226
+
227
+ ``` arduino
228
+ #include "Arduino_H7_Video.h"
229
+ #include "lvgl.h"
230
+ #include "Arduino_GigaDisplayTouch.h"
231
+
232
+ Arduino_H7_Video Display(800, 480, GigaDisplayShield);
233
+ Arduino_GigaDisplayTouch TouchDetector;
234
+
235
+ void setup() {
236
+ Display.begin();
237
+ TouchDetector.begin();
238
+
239
+ lv_obj_t * screen = lv_obj_create(lv_scr_act());
240
+ lv_obj_set_size(screen, Display.width(), Display.height());
241
+
242
+ static lv_coord_t col_dsc[] = { 500, LV_GRID_TEMPLATE_LAST};
243
+ static lv_coord_t row_dsc[] = { 400, LV_GRID_TEMPLATE_LAST};
244
+
245
+ lv_obj_t * grid = lv_obj_create(lv_scr_act());
246
+
247
+ lv_obj_set_grid_dsc_array(grid, col_dsc, row_dsc);
248
+
249
+ lv_obj_set_size(grid, Display.width(), Display.height());
250
+
251
+ lv_obj_center(grid);
252
+
253
+ lv_obj_t * obj;
254
+
255
+ obj = lv_obj_create(grid);
256
+ lv_obj_set_grid_cell(obj, LV_GRID_ALIGN_STRETCH, 0, 1,
257
+ LV_GRID_ALIGN_STRETCH, 0, 1);
258
+ lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN);
259
+
260
+ lv_obj_t * cb;
261
+ cb = lv_checkbox_create(obj);
262
+ lv_checkbox_set_text(cb, "Apple");
263
+
264
+ cb = lv_checkbox_create(obj);
265
+ lv_checkbox_set_text(cb, "Banana");
266
+ lv_obj_add_state(cb, LV_STATE_CHECKED);
267
+ }
268
+
269
+ void loop() {
270
+ lv_timer_handler();
271
+ }
272
+
273
+ ```
274
+
180
275
### Radio Button
181
276
182
277
A radio button is created in the same way as a checkbox, but with some additional calls to change the style of the element. Adding these two style elements will allow for them to be added to the checkbox options.
@@ -202,6 +297,69 @@ The size of the radio button is set with `lv_style_set_radius`. To make the radi
202
297
203
298
![ Radio buttons rendered on the Display Shield with LVGL] ( assets/radio-buttons.svg )
204
299
300
+ ### Full Example
301
+
302
+ ``` arduino
303
+ #include "Arduino_H7_Video.h"
304
+ #include "lvgl.h"
305
+ #include "Arduino_GigaDisplayTouch.h"
306
+
307
+ Arduino_H7_Video Display(800, 480, GigaDisplayShield);
308
+ Arduino_GigaDisplayTouch TouchDetector;
309
+
310
+ void setup() {
311
+ Display.begin();
312
+ TouchDetector.begin();
313
+
314
+ lv_obj_t * screen = lv_obj_create(lv_scr_act());
315
+ lv_obj_set_size(screen, Display.width(), Display.height());
316
+
317
+ static lv_coord_t col_dsc[] = { 500, LV_GRID_TEMPLATE_LAST};
318
+ static lv_coord_t row_dsc[] = { 400, LV_GRID_TEMPLATE_LAST};
319
+
320
+ lv_obj_t * grid = lv_obj_create(lv_scr_act());
321
+
322
+ lv_obj_set_grid_dsc_array(grid, col_dsc, row_dsc);
323
+
324
+ lv_obj_set_size(grid, Display.width(), Display.height());
325
+
326
+ lv_obj_center(grid);
327
+
328
+ lv_obj_t * obj;
329
+
330
+ obj = lv_obj_create(grid);
331
+ lv_obj_set_grid_cell(obj, LV_GRID_ALIGN_STRETCH, 0, 1,
332
+ LV_GRID_ALIGN_STRETCH, 0, 1);
333
+ lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN);
334
+
335
+ lv_obj_t * cb;
336
+
337
+ static lv_style_t style_radio;
338
+ static lv_style_t style_radio_chk;
339
+ lv_style_init(&style_radio);
340
+ lv_style_set_radius(&style_radio, LV_RADIUS_CIRCLE);
341
+ lv_style_init(&style_radio_chk);
342
+ lv_style_set_bg_img_src(&style_radio_chk, NULL);
343
+
344
+ cb = lv_checkbox_create(obj);
345
+ lv_checkbox_set_text(cb, "Lemon");
346
+ lv_obj_add_flag(cb, LV_OBJ_FLAG_EVENT_BUBBLE);
347
+ lv_obj_add_style(cb, &style_radio, LV_PART_INDICATOR);
348
+ lv_obj_add_style(cb, &style_radio_chk, LV_PART_INDICATOR | LV_STATE_CHECKED);
349
+
350
+ cb = lv_checkbox_create(obj);
351
+ lv_checkbox_set_text(cb, "Melon");
352
+ lv_obj_add_flag(cb, LV_OBJ_FLAG_EVENT_BUBBLE);
353
+ lv_obj_add_style(cb, &style_radio, LV_PART_INDICATOR);
354
+ lv_obj_add_style(cb, &style_radio_chk, LV_PART_INDICATOR | LV_STATE_CHECKED);
355
+ lv_obj_add_state(cb, LV_STATE_CHECKED);
356
+ }
357
+
358
+ void loop() {
359
+ lv_timer_handler();
360
+ }
361
+ ```
362
+
205
363
### Slider
206
364
207
365
` obj ` will be a pointer that will be used to hold the information about the screenspace information for the slider. The ` slider ` pointer will be used for the elements of the slider itself. The ` label ` pointer will be used for the text that will attached to the slider.
@@ -234,6 +392,57 @@ If you want a label by your slider it can be created like you would create any o
234
392
235
393
![ Slider rendered on the Display Shield with LVGL] ( assets/slider.svg )
236
394
395
+ ### Full Example
396
+
397
+ ``` arduino
398
+ #include "Arduino_H7_Video.h"
399
+ #include "Arduino_GigaDisplayTouch.h"
400
+
401
+ #include "lvgl.h"
402
+
403
+ Arduino_H7_Video Display(800, 480, GigaDisplayShield); /* Arduino_H7_Video Display(1024, 768, USBCVideo); */
404
+ Arduino_GigaDisplayTouch TouchDetector;
405
+
406
+ void setup() {
407
+ Display.begin();
408
+ TouchDetector.begin();
409
+
410
+ lv_obj_t * screen = lv_obj_create(lv_scr_act());
411
+ lv_obj_set_size(screen, Display.width(), Display.height());
412
+
413
+ static lv_coord_t col_dsc[] = { 500, LV_GRID_TEMPLATE_LAST};
414
+ static lv_coord_t row_dsc[] = { 400, LV_GRID_TEMPLATE_LAST};
415
+
416
+ lv_obj_t * grid = lv_obj_create(lv_scr_act());
417
+
418
+ lv_obj_set_grid_dsc_array(grid, col_dsc, row_dsc);
419
+
420
+ lv_obj_set_size(grid, Display.width(), Display.height());
421
+
422
+ lv_obj_center(grid);
423
+
424
+ lv_obj_t * label;
425
+ lv_obj_t * obj;
426
+
427
+ obj = lv_obj_create(grid);
428
+ lv_obj_set_grid_cell(obj, LV_GRID_ALIGN_STRETCH, 0, 1,
429
+ LV_GRID_ALIGN_STRETCH, 0, 1);
430
+ lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN);
431
+
432
+ lv_obj_t * slider = lv_slider_create(obj);
433
+ lv_slider_set_value(slider, 75, LV_ANIM_OFF);
434
+ lv_obj_center(slider);
435
+ label = lv_label_create(obj);
436
+ lv_label_set_text(label, "Drag me!");
437
+ lv_obj_align_to(label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
438
+
439
+ }
440
+
441
+ void loop() {
442
+ lv_timer_handler();
443
+ }
444
+ ```
445
+
237
446
### Bar
238
447
239
448
To make a bar, like a loading bar, we need to include some animation. Let's first set up the slider itself and then move on to the animation.
@@ -307,6 +516,69 @@ static void set_bar_val(void * bar, int32_t val) {
307
516
308
517
![ A bar rendered on the Display Shield with LVGL] ( assets/bar.gif )
309
518
519
+ ### Full Example
520
+
521
+ ``` arduino
522
+ #include "Arduino_H7_Video.h"
523
+ #include "Arduino_GigaDisplayTouch.h"
524
+
525
+ #include "lvgl.h"
526
+
527
+ Arduino_H7_Video Display(800, 480, GigaDisplayShield); /* Arduino_H7_Video Display(1024, 768, USBCVideo); */
528
+ Arduino_GigaDisplayTouch TouchDetector;
529
+
530
+ static void set_slider_val(void * bar, int32_t val) {
531
+ lv_bar_set_value((lv_obj_t *)bar, val, LV_ANIM_ON);
532
+ }
533
+
534
+ void setup() {
535
+ Display.begin();
536
+ TouchDetector.begin();
537
+
538
+ lv_obj_t * screen = lv_obj_create(lv_scr_act());
539
+ lv_obj_set_size(screen, Display.width(), Display.height());
540
+
541
+ static lv_coord_t col_dsc[] = { 500, LV_GRID_TEMPLATE_LAST};
542
+ static lv_coord_t row_dsc[] = { 400, LV_GRID_TEMPLATE_LAST};
543
+
544
+ lv_obj_t * grid = lv_obj_create(lv_scr_act());
545
+
546
+ lv_obj_set_grid_dsc_array(grid, col_dsc, row_dsc);
547
+
548
+ lv_obj_set_size(grid, Display.width(), Display.height());
549
+
550
+ lv_obj_center(grid);
551
+
552
+ lv_obj_t * label;
553
+ lv_obj_t * obj;
554
+
555
+ obj = lv_obj_create(grid);
556
+ lv_obj_set_grid_cell(obj, LV_GRID_ALIGN_STRETCH, 0, 1,
557
+ LV_GRID_ALIGN_STRETCH, 0, 1);
558
+ lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN);
559
+
560
+ lv_obj_t * bar = lv_bar_create(obj);
561
+ lv_obj_set_size(bar, 200, 20);
562
+ lv_obj_center(bar);
563
+ lv_bar_set_value(bar, 70, LV_ANIM_OFF);
564
+
565
+ lv_anim_t a;
566
+ lv_anim_init(&a);
567
+ lv_anim_set_exec_cb(&a, set_slider_val);
568
+ lv_anim_set_time(&a, 3000);
569
+ lv_anim_set_playback_time(&a, 3000);
570
+ lv_anim_set_var(&a, bar);
571
+ lv_anim_set_values(&a, 0, 100);
572
+ lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
573
+ lv_anim_start(&a);
574
+
575
+ }
576
+
577
+ void loop() {
578
+ lv_timer_handler();
579
+ }
580
+ ```
581
+
310
582
### Button
311
583
312
584
A button will need two parts, the design of the button itself and the callback event function which determines what happens when the button is pressed. Let's start with designing the button.
@@ -360,6 +632,64 @@ static void button_event_callback(lv_event_t * e) {
360
632
![ A button rendered on the Display Shield with LVGL] ( assets/button.svg )
361
633
![ Button when it has been pressed] ( assets/button-clicked.svg )
362
634
635
+ ### Full Example
636
+
637
+ ``` arduino
638
+ #include "Arduino_H7_Video.h"
639
+ #include "lvgl.h"
640
+ #include "Arduino_GigaDisplayTouch.h"
641
+
642
+ Arduino_H7_Video Display(800, 480, GigaDisplayShield);
643
+ Arduino_GigaDisplayTouch TouchDetector;
644
+
645
+ static void btn_event_cb(lv_event_t * e) {
646
+ lv_obj_t * btn = lv_event_get_target(e);
647
+ lv_obj_t * label = lv_obj_get_child(btn, 0);
648
+ lv_label_set_text_fmt(label, "Clicked!");
649
+ }
650
+
651
+ void setup() {
652
+ Display.begin();
653
+ TouchDetector.begin();
654
+
655
+ lv_obj_t * screen = lv_obj_create(lv_scr_act());
656
+ lv_obj_set_size(screen, Display.width(), Display.height());
657
+
658
+ static lv_coord_t col_dsc[] = { 500, LV_GRID_TEMPLATE_LAST};
659
+ static lv_coord_t row_dsc[] = { 400, LV_GRID_TEMPLATE_LAST};
660
+
661
+ lv_obj_t * grid = lv_obj_create(lv_scr_act());
662
+
663
+ lv_obj_set_grid_dsc_array(grid, col_dsc, row_dsc);
664
+
665
+ lv_obj_set_size(grid, Display.width(), Display.height());
666
+
667
+ lv_obj_center(grid);
668
+
669
+ lv_obj_t * label;
670
+ lv_obj_t * obj;
671
+
672
+ obj = lv_obj_create(grid);
673
+ lv_obj_set_grid_cell(obj, LV_GRID_ALIGN_STRETCH, 0, 1,
674
+ LV_GRID_ALIGN_STRETCH, 0, 1);
675
+ lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN);
676
+
677
+ lv_obj_t * btn = lv_btn_create(obj);
678
+ lv_obj_set_size(btn, 100, 40);
679
+ lv_obj_center(btn);
680
+ lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_CLICKED, NULL);
681
+
682
+ label = lv_label_create(btn);
683
+ lv_label_set_text(label, "Click me!");
684
+ lv_obj_center(label);
685
+
686
+ }
687
+
688
+ void loop() {
689
+ lv_timer_handler();
690
+ }
691
+ ```
692
+
363
693
## Conclusion
364
694
365
695
This guide went through the building blocks of the different components that can be implemented with LVGL. To see these examples in a full running example sketch go to ** File > Examples > Arduino_H7_Video > LVGLDemo** .
0 commit comments