1414#include < LSM6DSO32Sensor.h>
1515
1616#ifdef ARDUINO_SAM_DUE
17- #define DEV_I2C Wire1
17+ #define DEV_I2C Wire1
1818#elif defined(ARDUINO_ARCH_STM32)
19- #define DEV_I2C Wire
19+ #define DEV_I2C Wire
2020#elif defined(ARDUINO_ARCH_AVR)
21- #define DEV_I2C Wire
21+ #define DEV_I2C Wire
2222#else
23- #define DEV_I2C Wire
23+ #define DEV_I2C Wire
2424#endif
2525#define SerialPort Serial
2626
@@ -36,15 +36,16 @@ char report[256];
3636void INT1Event_cb ();
3737void sendOrientation ();
3838
39- void setup () {
39+ void setup ()
40+ {
4041 // Led.
4142 pinMode (LED_BUILTIN, OUTPUT);
4243 // Initialize serial for output.
4344 SerialPort.begin (115200 );
4445
4546 // Initialize I2C bus.
4647 DEV_I2C.begin ();
47-
48+
4849 // Int1 pin input
4950 pinMode (IMU_INT_1, INPUT);
5051
@@ -53,26 +54,24 @@ void setup() {
5354 accGyr.Enable_6D_Orientation (LSM6DSO32_INT1_PIN);
5455}
5556
56- void loop () {
57+ void loop ()
58+ {
5759
5860 int int_val = digitalRead (IMU_INT_1);
59- if (int_val && !mems_event)
60- {
61+ if (int_val && !mems_event) {
6162 mems_event = 1 ;
6263 }
6364
64- if (mems_event)
65- {
66- mems_event=0 ;
65+ if (mems_event) {
66+ mems_event = 0 ;
6767 LSM6DSO32_Event_Status_t status;
6868 accGyr.Get_X_Event_Status (&status);
69- if (status.D6DOrientationStatus )
70- {
69+ if (status.D6DOrientationStatus ) {
7170 sendOrientation ();
7271 // Led blinking.
7372 digitalWrite (LED_BUILTIN, HIGH);
7473 delay (100 );
75- digitalWrite (LED_BUILTIN, LOW);
74+ digitalWrite (LED_BUILTIN, LOW);
7675 }
7776 }
7877}
@@ -93,70 +92,63 @@ void sendOrientation()
9392 accGyr.Get_6D_Orientation_ZL (&zl);
9493 accGyr.Get_6D_Orientation_ZH (&zh);
9594
96- if ( xl == 0 && yl == 0 && zl == 0 && xh == 0 && yh == 1 && zh == 0 )
97- {
98- sprintf ( report, " \r\n ________________ " \
99- " \r\n | | " \
100- " \r\n | * | " \
101- " \r\n | | " \
102- " \r\n | | " \
103- " \r\n | | " \
104- " \r\n | | " \
105- " \r\n |________________| \r\n " );
95+ if (xl == 0 && yl == 0 && zl == 0 && xh == 0 && yh == 1 && zh == 0 ) {
96+ sprintf (report, " \r\n ________________ " \
97+ " \r\n | | " \
98+ " \r\n | * | " \
99+ " \r\n | | " \
100+ " \r\n | | " \
101+ " \r\n | | " \
102+ " \r\n | | " \
103+ " \r\n |________________| \r\n " );
106104 }
107105
108- else if ( xl == 1 && yl == 0 && zl == 0 && xh == 0 && yh == 0 && zh == 0 )
109- {
110- sprintf ( report, " \r\n ________________ " \
111- " \r\n | | " \
112- " \r\n | * | " \
113- " \r\n | | " \
114- " \r\n | | " \
115- " \r\n | | " \
116- " \r\n | | " \
117- " \r\n |________________| \r\n " );
106+ else if (xl == 1 && yl == 0 && zl == 0 && xh == 0 && yh == 0 && zh == 0 ) {
107+ sprintf (report, " \r\n ________________ " \
108+ " \r\n | | " \
109+ " \r\n | * | " \
110+ " \r\n | | " \
111+ " \r\n | | " \
112+ " \r\n | | " \
113+ " \r\n | | " \
114+ " \r\n |________________| \r\n " );
118115 }
119116
120- else if ( xl == 0 && yl == 0 && zl == 0 && xh == 1 && yh == 0 && zh == 0 )
121- {
122- sprintf ( report, " \r\n ________________ " \
123- " \r\n | | " \
124- " \r\n | | " \
125- " \r\n | | " \
126- " \r\n | | " \
127- " \r\n | | " \
128- " \r\n | * | " \
129- " \r\n |________________| \r\n " );
117+ else if (xl == 0 && yl == 0 && zl == 0 && xh == 1 && yh == 0 && zh == 0 ) {
118+ sprintf (report, " \r\n ________________ " \
119+ " \r\n | | " \
120+ " \r\n | | " \
121+ " \r\n | | " \
122+ " \r\n | | " \
123+ " \r\n | | " \
124+ " \r\n | * | " \
125+ " \r\n |________________| \r\n " );
130126 }
131127
132- else if ( xl == 0 && yl == 1 && zl == 0 && xh == 0 && yh == 0 && zh == 0 )
133- {
134- sprintf ( report, " \r\n ________________ " \
135- " \r\n | | " \
136- " \r\n | | " \
137- " \r\n | | " \
138- " \r\n | | " \
139- " \r\n | | " \
140- " \r\n | * | " \
141- " \r\n |________________| \r\n " );
128+ else if (xl == 0 && yl == 1 && zl == 0 && xh == 0 && yh == 0 && zh == 0 ) {
129+ sprintf (report, " \r\n ________________ " \
130+ " \r\n | | " \
131+ " \r\n | | " \
132+ " \r\n | | " \
133+ " \r\n | | " \
134+ " \r\n | | " \
135+ " \r\n | * | " \
136+ " \r\n |________________| \r\n " );
142137 }
143138
144- else if ( xl == 0 && yl == 0 && zl == 0 && xh == 0 && yh == 0 && zh == 1 )
145- {
146- sprintf ( report, " \r\n __*_____________ " \
147- " \r\n |________________| \r\n " );
139+ else if (xl == 0 && yl == 0 && zl == 0 && xh == 0 && yh == 0 && zh == 1 ) {
140+ sprintf (report, " \r\n __*_____________ " \
141+ " \r\n |________________| \r\n " );
148142 }
149143
150- else if ( xl == 0 && yl == 0 && zl == 1 && xh == 0 && yh == 0 && zh == 0 )
151- {
152- sprintf ( report, " \r\n ________________ " \
153- " \r\n |________________| " \
154- " \r\n * \r\n " );
144+ else if (xl == 0 && yl == 0 && zl == 1 && xh == 0 && yh == 0 && zh == 0 ) {
145+ sprintf (report, " \r\n ________________ " \
146+ " \r\n |________________| " \
147+ " \r\n * \r\n " );
155148 }
156149
157- else
158- {
159- sprintf ( report, " None of the 6D orientation axes is set in LSM6DSO - accelerometer.\r\n " );
150+ else {
151+ sprintf (report, " None of the 6D orientation axes is set in LSM6DSO - accelerometer.\r\n " );
160152 }
161153
162154 SerialPort.print (report);
0 commit comments