-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathE_Bicycle_v3.ino
404 lines (338 loc) · 15 KB
/
E_Bicycle_v3.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
#include "BluetoothSerial.h"
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
// screen settings
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
// Blu deffine
BluetoothSerial SerialBT;
// 25, 26, 16, 0, 2, 14, 12, 13, 15, 36, 39 pins
// encode valu - 12
// 4RPM - 28.27 cm = 0.2827 m
// ------------------------------- ESP pins ----------------------------------
const int BLU_LED = 16; // B 66
const int ELC_MOD = 14; // E-on 69, E-off 70
const int AUTO_MOD = 0; // A-on 65, A-0ff 67
const int Break_MOD = 2; // S-stop 83, R-run 82
const int EncoderPin = 25;
const int potPin = 39;
const int I_sen = 36;
const int V_sen = 26;
const int M_PWM = 15;
const int M_INA = 13;
const int M_INB = 12;
// ----------------------------------------------------------------------
// Mode status -----------------------------------------------------------
int BLU_MOD =0;
int E_MOD = 0;
int A_MOD = 0;
int B_MOD = 0;
int LoopCount =0;
// -----------------------------------------------------------------------
// sensor veriable -------------------------------------------------------
float potValue = 0;
float V_value = 0;
float I_value = 0;
// ------------------------------------------------------------------------
// BLU veriables ----------------------------------------------------------------
int count = 0;
float speed = 0;
int soc = 0;
int distance = 0;
char Char_Sp[8];
char Char_Soc[8];
char Char_Dis[8];
char data[50];
// -------------------------------------------------------------------------------
// Setting PWM properties ---------------------------------------------------------------------
const int freq = 30000;
const int pwmChannel = 0;
const int resolution = 8;
int dutyCycle = 0;
int NotMapDutyCycle;
// ---------------------------------------------------------------------------
// RPM sensor const -----------------------------------------------------------------
const byte PulsesPerRevolution = 12;
const unsigned long ZeroTimeout = 100000;
const byte numReadings = 2;
volatile unsigned long LastTimeWeMeasured;
volatile unsigned long PeriodBetweenPulses = ZeroTimeout + 1000;
volatile unsigned long PeriodAverage = ZeroTimeout + 1000;
unsigned long FrequencyRaw;
unsigned long FrequencyReal;
unsigned long RPM;
unsigned int PulseCounter = 1;
unsigned long PeriodSum;
unsigned long LastTimeCycleMeasure = LastTimeWeMeasured;
unsigned long CurrentMicros = micros();
unsigned int AmountOfReadings = 1;
unsigned int ZeroDebouncingExtra;
unsigned long readings[numReadings];
unsigned long readIndex;
unsigned long total;
unsigned long average;
float TotalCount =0;
// ---------------------------------------------------------------------
// bitmap image -----------------------------------------------------------------
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
static const uint8_t image_data_Saraarray[1024] ={
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xa0, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0xfd, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x80, 0x00,
0x00, 0x08, 0x10, 0x00, 0x82, 0x21, 0x08, 0x23, 0xfe, 0xb0, 0x01, 0x00, 0x08, 0x80, 0x04, 0x00,
0x00, 0x20, 0x00, 0x84, 0x00, 0x00, 0x00, 0x7f, 0x71, 0xfc, 0x10, 0x00, 0x00, 0x00, 0x00, 0x04,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3a, 0x89, 0xac, 0x00, 0x00, 0x00, 0x02, 0x00, 0x10,
0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x39, 0xfe, 0x46, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x47, 0xff, 0xfa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0x00, 0x00, 0x02, 0x00, 0x08, 0x80, 0x40, 0x6f, 0xf9, 0xf3, 0x00, 0x00, 0x00, 0x20, 0x10, 0x00,
0x08, 0x00, 0x00, 0x10, 0x40, 0x00, 0x00, 0x1f, 0xff, 0xe7, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x3f, 0xff, 0x6d, 0x08, 0x04, 0x00, 0x01, 0x00, 0x00,
0x00, 0x08, 0x00, 0x00, 0x00, 0x0f, 0x81, 0xb3, 0x63, 0xf2, 0x60, 0x40, 0x10, 0x00, 0x00, 0x00,
0x00, 0x40, 0x10, 0x40, 0x00, 0x0f, 0x8f, 0xb7, 0x79, 0xea, 0xf0, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x80, 0x3d, 0xff, 0x7e, 0xff, 0xaa, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x10,
0x00, 0x00, 0x00, 0x00, 0x1e, 0x7f, 0xf7, 0x7c, 0xff, 0xf4, 0xdc, 0x00, 0x40, 0x00, 0x10, 0x00,
0x04, 0x00, 0x00, 0x00, 0x1e, 0xed, 0xbd, 0x7c, 0xff, 0x6d, 0xfe, 0x01, 0x01, 0x08, 0x40, 0x00,
0x00, 0x00, 0x01, 0x00, 0x3c, 0xff, 0xef, 0x7f, 0xf7, 0xfc, 0xdb, 0x08, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x10, 0x04, 0x3c, 0x5b, 0x7f, 0x2f, 0xe3, 0xfd, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x21, 0x00, 0x00, 0x1c, 0x3f, 0xed, 0xaa, 0x5b, 0x6c, 0xde, 0x00, 0x00, 0x00, 0x00, 0x40,
0x00, 0x80, 0x00, 0x00, 0x1c, 0x1d, 0xbf, 0xab, 0xed, 0xf3, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1e, 0x1f, 0xf6, 0x9c, 0x3f, 0xce, 0xd8, 0x00, 0x00, 0x41, 0x01, 0x04,
0x04, 0x00, 0x00, 0x41, 0xc3, 0xb6, 0xdf, 0xdf, 0x7f, 0xdf, 0xf8, 0x00, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x02, 0x01, 0xfd, 0x9f, 0xfd, 0xcf, 0xfd, 0x1b, 0x6c, 0x00, 0x08, 0x00, 0x00, 0x00,
0x00, 0x00, 0x10, 0x03, 0xfe, 0xc3, 0xf7, 0xe7, 0xfe, 0x67, 0xfe, 0x02, 0x20, 0x00, 0x10, 0x00,
0x00, 0x00, 0x80, 0x00, 0x0e, 0xe8, 0x08, 0x11, 0xf7, 0x70, 0xda, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x02, 0x00, 0x01, 0xf8, 0xc5, 0x56, 0xa6, 0x5e, 0xf5, 0x3e, 0x00, 0x00, 0x02, 0x00, 0x40,
0x01, 0x08, 0x00, 0x01, 0xfe, 0xd5, 0x52, 0xb7, 0x09, 0xe5, 0x4f, 0x00, 0x00, 0x00, 0x00, 0x02,
0x04, 0x00, 0x00, 0x01, 0xff, 0xb5, 0x55, 0x4b, 0xef, 0x4a, 0xa7, 0xf8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x20, 0x40, 0xd1, 0x55, 0x53, 0xfb, 0x94, 0x93, 0xfc, 0x00, 0x08, 0x11, 0x00,
0x00, 0x00, 0x00, 0x00, 0xfe, 0xaa, 0x4a, 0xa9, 0xbe, 0x2a, 0xa8, 0xdc, 0x00, 0x20, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0xfc, 0xa4, 0x92, 0x55, 0xf0, 0xaa, 0xaa, 0xf8, 0x10, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x17, 0x52, 0x48, 0xab, 0xe5, 0x55, 0x55, 0x3c, 0x00, 0x00, 0x00, 0x08,
0x00, 0x00, 0x00, 0x00, 0x00, 0xa8, 0x16, 0x53, 0xb5, 0x52, 0xaa, 0xb4, 0x00, 0x00, 0x00, 0x00,
0x00, 0x20, 0x10, 0x00, 0x3f, 0x4b, 0xfe, 0xab, 0xe5, 0x55, 0x55, 0x1c, 0x01, 0x00, 0x20, 0x00,
0x08, 0x00, 0x40, 0x08, 0x3f, 0xff, 0xfe, 0x4a, 0xea, 0xa5, 0x2a, 0xcc, 0x00, 0x00, 0x01, 0x00,
0x00, 0x02, 0x00, 0x00, 0x1d, 0xbe, 0xda, 0x53, 0xe5, 0x50, 0xd2, 0x4c, 0x08, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x02, 0xf7, 0xfe, 0xab, 0xea, 0x54, 0x15, 0x50, 0x00, 0x00, 0x00, 0x04,
0x00, 0x00, 0x00, 0x80, 0x00, 0x7d, 0xb6, 0x57, 0xa5, 0x44, 0xe5, 0x40, 0x00, 0x08, 0x04, 0x00,
0x00, 0x40, 0x00, 0x00, 0x80, 0x77, 0xfe, 0x53, 0xea, 0xaa, 0xca, 0xa0, 0x00, 0x20, 0x40, 0x00,
0x00, 0x00, 0x00, 0x02, 0x00, 0x7f, 0x6e, 0xa7, 0x65, 0x50, 0xd5, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x37, 0xfa, 0x57, 0xe9, 0x25, 0x94, 0xa0, 0x02, 0x00, 0x00, 0x10,
0x08, 0x04, 0x10, 0x00, 0x00, 0x3d, 0xbe, 0xa3, 0xc5, 0x51, 0xaa, 0x40, 0x10, 0x00, 0x00, 0x00,
0x00, 0x10, 0x01, 0x00, 0x00, 0x1f, 0xef, 0x1b, 0x6a, 0xa9, 0x25, 0x00, 0x00, 0x00, 0x02, 0x00,
0x00, 0x40, 0x00, 0x08, 0x04, 0x1b, 0x7d, 0x47, 0xea, 0x89, 0x50, 0x80, 0x00, 0x00, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xf7, 0x73, 0xe5, 0x40, 0x0a, 0x00, 0x40, 0x01, 0x00, 0x00,
0x00, 0x00, 0x20, 0x00, 0x00, 0x7b, 0xbf, 0x7f, 0xa0, 0x3c, 0x64, 0x00, 0x00, 0x10, 0x00, 0x04,
0x04, 0x00, 0x00, 0x00, 0x20, 0xfe, 0xed, 0x7e, 0xff, 0xfd, 0x92, 0x00, 0x00, 0x40, 0x00, 0x20,
0x00, 0x00, 0x00, 0x80, 0x00, 0xf7, 0xff, 0x6f, 0xff, 0xf5, 0xc1, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x02, 0x00, 0x7f, 0x6f, 0x3f, 0xff, 0xdd, 0xf6, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x00, 0x1b, 0xfd, 0x8b, 0xbf, 0xe9, 0x6c, 0x04, 0x00, 0x00, 0x01, 0x00,
0x00, 0x44, 0x04, 0x00, 0x00, 0x0e, 0xe7, 0xa0, 0x50, 0x18, 0xf8, 0x10, 0x04, 0x00, 0x20, 0x00,
0x04, 0x00, 0x00, 0x08, 0x04, 0x07, 0xc1, 0x9d, 0x45, 0xe0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x10, 0x03, 0x00, 0x25, 0x56, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x10,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x15, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
0x20, 0x00, 0x08, 0x00, 0x40, 0x00, 0x00, 0x15, 0x54, 0x00, 0x00, 0x00, 0x04, 0x10, 0x00, 0x00,
0x00, 0x40, 0x20, 0x00, 0x00, 0x00, 0x00, 0x14, 0xa8, 0x00, 0x00, 0x10, 0x10, 0x00, 0x08, 0x00,
0x00, 0x04, 0x00, 0x01, 0x00, 0x40, 0x00, 0x0f, 0xf8, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x04,
0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x10,
0x02, 0x00, 0x00, 0x80, 0x00, 0x04, 0x42, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x10, 0x40, 0x80,
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00
};
// --------------------------------------------------------------------------------
void setup() {
Serial.begin(115200);
SerialBT.begin("E_Bicycle_v1"); // Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
// Start I2C Communication SDA = 5 and SCL = 4 on Wemos Lolin32 ESP32 with built-in SSD1306 OLED
Wire.begin(5, 4);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C, false, false)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
delay(2000); // Pause for 2 seconds
// Clear the buffer.
display.clearDisplay();
// Draw bitmap on the screen
display.drawBitmap(0, 0, image_data_Saraarray, 128, 64, 1);
display.display();
// Interrupt set
attachInterrupt(digitalPinToInterrupt(EncoderPin), Pulse_Event, FALLING);
// pinMode set
pinMode(BLU_LED, OUTPUT);
pinMode(ELC_MOD, OUTPUT);
pinMode(AUTO_MOD, OUTPUT);
pinMode(Break_MOD, OUTPUT);
pinMode(M_PWM, OUTPUT);
pinMode(M_INA, OUTPUT);
pinMode(M_INB, OUTPUT);
pinMode(potPin, INPUT);
pinMode(I_sen, INPUT);
pinMode(V_sen, INPUT);
// OnStart LED
digitalWrite(BLU_LED, LOW);
digitalWrite(ELC_MOD, LOW);
digitalWrite(AUTO_MOD, LOW);
digitalWrite(Break_MOD, LOW);
// Turn off motors - Initial state
digitalWrite(M_INA, LOW);
digitalWrite(M_INB, LOW);
digitalWrite(M_PWM, LOW);
// configure LED PWM functionalitites
ledcSetup(pwmChannel, freq, resolution);
// // attach the channel to the GPIO to be controlled
ledcAttachPin(M_PWM, pwmChannel);
}
void loop() {
// BLU RX read -----------------------------------------------------------
if (SerialBT.available()) {
char a = SerialBT.read();
Serial.write(a);
if (a==66) { // blu
digitalWrite(BLU_LED, HIGH);
}
else if (a==83) { // stop
digitalWrite(Break_MOD, HIGH);
B_MOD=1;
}
else if (a==82) { // run
digitalWrite(Break_MOD, LOW);
B_MOD=0;
}
else if (a==69) { // Electric mode on
digitalWrite(ELC_MOD, HIGH);
E_MOD =1;
}
else if (a==70) { // electric mode off
digitalWrite(ELC_MOD, LOW);
E_MOD =0;
}
else if (a==65) { // auto mode on
digitalWrite(AUTO_MOD, HIGH);
A_MOD =1;
}
else if (a==67) { // auto mode off
digitalWrite(AUTO_MOD, LOW);
A_MOD =0;
}
}
// -----------------------------------------------------------------------------
delay(20);
// pot read ---------------------------------------------------------------
potValue = (analogRead(potPin)/4095.0)*255;
if (potValue <=100) {
potValue=100;
} else if (potValue >=200) {
potValue = 200;
}
dutyCycle = map(potValue, 100,200,0,255);
// Serial.println(dutyCycle);
// V_value = analogRead(V_sen);
// I_value = analogRead(I_sen)*5/(4095.0*0.140);
soc = 89.5;
// Serial.println(soc);
if (A_MOD==1) {
if (B_MOD==0){
digitalWrite(M_INA, LOW);
digitalWrite(M_INB, HIGH);
ledcWrite(pwmChannel, 200);
}
else if (B_MOD==1) {
digitalWrite(M_INA, LOW);
digitalWrite(M_INB, LOW);
ledcWrite(pwmChannel, 0);
}
}
else if (E_MOD==1) {
digitalWrite(M_INA, LOW);
digitalWrite(M_INB, HIGH);
ledcWrite(pwmChannel, dutyCycle);
}
else if (E_MOD==0){
digitalWrite(M_INA, LOW);
digitalWrite(M_INB, LOW);
ledcWrite(pwmChannel, 0);
}
// ------------------------------------------------------------------------
// RPM read ----------------------------------------------------------------
LastTimeCycleMeasure = LastTimeWeMeasured;
CurrentMicros = micros();
if (CurrentMicros < LastTimeCycleMeasure) {
LastTimeCycleMeasure = CurrentMicros;
}
FrequencyRaw = 10000000000 / PeriodAverage;
if (PeriodBetweenPulses > ZeroTimeout - ZeroDebouncingExtra || CurrentMicros - LastTimeCycleMeasure > ZeroTimeout - ZeroDebouncingExtra) {
FrequencyRaw = 0; // Set frequency as 0.
ZeroDebouncingExtra = 2000;
} else {
ZeroDebouncingExtra = 0;
}
FrequencyReal = FrequencyRaw / 100000;
TotalCount = TotalCount + FrequencyRaw/12;
RPM = FrequencyRaw / PulsesPerRevolution * 60;
RPM = RPM / 10000;
total = total - readings[readIndex];
readings[readIndex] = RPM;
total = total + readings[readIndex];
readIndex = readIndex + 1;
if (readIndex >= numReadings) {
readIndex = 0;
}
average = total / numReadings;
speed = RPM*7.53*60/100000; // m_p_s
// Serial.println(speed);
// Serial.println(TotalCount);
distance = TotalCount*7.53/(12*1000000);
// ----------------------------------------------------------------------------
// BLU protocl --------------------------------------------------------------
// if (count > 50) {
// speed = speed + 1;
// soc = soc + 2;
// distance = distance + 3;
// if (distance >99) {
// speed = 0;
// soc = 0;
// distance = 0;
// }
// count = 0;
// }
// count = count + 1;
data[0] = 0;
strcat(data,"/");
dtostrf(speed,2,1,Char_Sp);
strcat(data,Char_Sp);
strcat(data,":");
dtostrf(soc,2,1,Char_Soc);
strcat(data,Char_Soc);
strcat(data,":");
dtostrf(distance,2,1,Char_Dis);
strcat(data,Char_Dis);
strcat(data,"/");
for (int c=0; c< strlen(data); c++){
SerialBT.write(data[c]);
}
// -----------------------------------------------------------------------
}
// inturrupt function ---------------------------------------------------------
void Pulse_Event() {
PeriodBetweenPulses = micros() - LastTimeWeMeasured;
LastTimeWeMeasured = micros();
if (PulseCounter >= AmountOfReadings) {
PeriodAverage = PeriodSum / AmountOfReadings;
PulseCounter = 1;
PeriodSum = PeriodBetweenPulses;
int RemapedAmountOfReadings = map(PeriodBetweenPulses, 40000, 5000, 1, 10);
RemapedAmountOfReadings = constrain(RemapedAmountOfReadings, 1, 10);
AmountOfReadings = RemapedAmountOfReadings;
} else {
PulseCounter++;
PeriodSum = PeriodSum + PeriodBetweenPulses;
}
}
// -------------------------------------------------------------------------------