You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -43,41 +43,37 @@ Any image could be used here. This tutorial will use the following image of the
43
43
Now to first get the readings from the IMU we will use the `"Arduino_BMI270_BMM150.h"` library. Then we need to set the image name variables with `extern const lv_img_dsc_t arduino_logo_1;`. To use the IMU set it up with `BoschSensorClass imu(Wire1);`.
initialize the display with `Display.begin();` and start recieving IMU readings with `imu.begin();`. Next, we can give the image its attributes.
59
56
60
57
```arduino
58
+
LV_IMG_DECLARE(img_arduinologo);
59
+
lv_obj_t * img;
60
+
61
61
void setup() {
62
62
Serial.begin(115200);
63
+
63
64
Display.begin();
64
65
imu.begin();
65
66
66
-
LV_IMG_DECLARE(arduino_logo_1);
67
-
lv_obj_t * obj;
68
-
obj = lv_obj_create(lv_scr_act());
69
-
lv_obj_set_size(obj, 350, 350);
70
-
71
-
avatar = lv_img_create(obj);
72
-
lv_img_set_src(avatar, &arduino_logo_1);
67
+
img = lv_img_create(lv_scr_act());
68
+
lv_img_set_src(img, &img_arduinologo);
69
+
lv_obj_align(img, LV_ALIGN_CENTER, 0, 0);
70
+
lv_img_set_pivot(img, (img_arduinologo.header.w)/2, (img_arduinologo.header.h)/2); /* Rotate around the center of the image */
73
71
}
74
-
75
72
```
76
73
77
74
Now all that is left is to change the image depending on the IMU readings. First, declare the variables that will hold the values. Then to assign them the IMU reading values use `imu.readAcceleration(x, y, z);`. Next, we use `if ()` statements to change the rotation variable depending on the readings we are getting. And at the end, we render the image with the correct rotation.
The easiest way to tell what values you are getting depending on the orientation of the device is to use a simple sketch, like the one below that will simply print the IMU values in the serial monitor. Take note of the values you are getting when you rotate the shield and you can use them in the previous sketch.
104
104
105
105
```arduino
@@ -125,10 +125,56 @@ void loop(){
125
125
}
126
126
```
127
127
128
+
### Full Sketch
129
+
128
130
Now to put it all together where the image will change depending on how we rotate the board and shield:
0 commit comments