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
After the libraries import, several variables and structures are declared that has to be with the Machine Learning implementation:
99
+
100
+
```arduino
101
+
#include "SilabsTFLiteMicro.h"
102
+
#include "Modulino.h"
103
+
104
+
#define SEQUENCE_LENGTH 200
105
+
#define SIGNAL_CHANNELS 3
106
+
107
+
#define GESTURE_COUNT 3
108
+
#define WING_GESTURE 0
109
+
#define RING_GESTURE 1
110
+
#define NO_GESTURE 2
111
+
112
+
#define DETECTION_THRESHOLD 0.5f
113
+
114
+
static TfLiteTensor* model_input;
115
+
static tflite::MicroInterpreter* interpreter;
116
+
static int input_length;
117
+
static TfLiteTensor *output;
118
+
119
+
typedef struct model_output {
120
+
float gesture[GESTURE_COUNT];
121
+
} model_output_t;
122
+
123
+
typedef float acc_data_t;
124
+
```
125
+
126
+
We define some function prototypes to manage the Modulino Pixels and the Modulino Movement accelerometer data. Also, the classes for the Modulinos are declared.
127
+
128
+
```arduino
129
+
ModulinoColor OFF(0, 0, 0);
130
+
ModulinoColor YELLOW(255, 255, 0);
131
+
132
+
ModulinoMovement imu;
133
+
ModulinoPixels leds;
134
+
135
+
void setPixel(int pixel, ModulinoColor color) {
136
+
leds.set(pixel, color, 25);
137
+
leds.show();
138
+
}
139
+
140
+
bool accelerometer_setup();
141
+
void accelerometer_read(acc_data_t* dst, int n);
142
+
```
143
+
In the `setup()` function, the **Tensorflow Lite model** is initialized alongside some modules support, including:
144
+
145
+
- Serial communication
146
+
- Modulino Pixels LEDs
147
+
- Modulino Movement IMU
148
+
149
+
At the beginning, relevant model parameters as the input tensor and its characteristics are printed in the Serial Monitor for debugging.
In the `loop()` function, a four steps process is executed as following:
208
+
209
+
1.**Significant movement detection:** The Nano Matter reads the accelerometer data searching for significant movement, if detected then the next step starts.
210
+
2.**Accelerometer values reading:** The model input buffer is filled with new accelerometer values and normalized in the model format.
211
+
3.**Inference run:** The inference is run, and its results are retrieved for visual feedback triggering.
212
+
4.**Feedback results:** The inference results are analysed, printed in the Serial Monitor and reflected on the Modulino Pixels.
0 commit comments