HCSR04 Library
HCSR04.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 2016 Jan Cozijnsen
3 
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
35 #ifndef HCSR04
36 #define HCSR04
37 
38 
41 
42 
43 #include "hwlib.hpp"
44 #include <cstring>
45 
47 enum class Unit {Centim, Inch, Ms, Kmh, Mh, Cms, mHz, Hz};
48 
51 public:
54 
56  //
62  virtual long long int measure(Unit unit = Unit::Centim) = 0;
63 };
64 
66 class hcsr04 : public distancemeter {
67 private:
68  hwlib::target::pin_out & trig;
69  hwlib::target::pin_in & echo;
70 
71 public:
73  hcsr04(hwlib::target::pin_out & trig, hwlib::target::pin_in & echo):
74  distancemeter(),
75  trig(trig),
76  echo(echo) {}
77 
79  long long int measure(Unit unit = Unit::Centim) {
80  long long int timestamp1 = 0, timestamp2 = 0, timedif = 0;
81  trig.set(0);
82  hwlib::wait_ms(10);
83  hwlib::now_us();
84  trig.set(1);
85  hwlib::wait_us(15);
86  trig.set(0);
87  while (echo.get() == 0) {}
88  timestamp1 = hwlib::now_us();
89  while (echo.get() == 1){}
90  timestamp2 = hwlib::now_us();
91 
92  timedif = timestamp2 - timestamp1;
93  switch (unit) {
94  case Unit::Centim : return timedif / 58;
95  case Unit::Inch : return timedif / 148;
96  default : hwlib::cout << "ERROR: Entered unit not available in this function\n"; return 0;
97  }
98  return 0;
99  }
100 };
101 
103 class speedometer {
104 
105 private:
107  distancemeter & meter;
108 
109 public:
110  speedometer(distancemeter & meter):
111  meter(meter) {}
112 
113 
115  // \n
127  long long int getSpeed(Unit unit = Unit::Ms, int delay = 10) {
128  int timestamp = hwlib::now_us();
129  long long int res1 = meter.measure();
130  hwlib::wait_ms(delay);
131  long long int res2 = meter.measure();
132  int timedif = (hwlib::now_us() - timestamp) / 1000;
133  long long int result = res1-res2;
134  switch(unit) {
135  case Unit::Ms : return ((result*10) / timedif);
136  case Unit::Kmh : return ((result*36) / timedif);
137  case Unit::Mh : return ((result * 22) / timedif);
138  case Unit::Cms : return ((result*1000) / timedif);
139  default : hwlib::cout << "ERROR: Entered unit not available in this function\n"; return 0;
140  }
141  return 0;
142  }
143 
145  //
150  int getFreq(int measurements, Unit unit = Unit::Hz, int delay1 = 10, int delay2 = 100) {
151  int switches = 0;
152  int timestamp = hwlib::now_us();
153  bool status = getSpeed(Unit::Cms) > 0;
154  for (int i = 0; i < measurements; i++) {
155  if (status) {
156  if (getSpeed(Unit::Cms, delay2) < 0) {
157  status = 0;
158  switches++;
159  }
160  }
161  else {
162  if (getSpeed(Unit::Cms, delay2) > 0) {
163  status = 1;
164  switches++;
165  }
166  }
167  hwlib::wait_ms(delay1);
168  }
169  int time = (hwlib::now_us() - timestamp) / 1000;
170  switch(unit) {
171  case Unit::Hz : return switches / (time / 1000);
172  case Unit::mHz : return (switches*1000) / (time /1000);
173  default : hwlib::cout << "ERROR: Entered unit not available in this function\n"; return 0;
174  }
175  return 0;
176  }
177 };
178 
180 class disparray {
181 private:
182  int bitmapsize[123] = {};
183 public:
184  hwlib::location bitmaps[123][20];
185 
186  disparray() {
187  //Initialization of bitmapsize;
188  bitmapsize[39] = 4;
189  bitmapsize[45] = 8;
190  bitmapsize[47] = 6;
191  bitmapsize[48] = 12;
192  bitmapsize[49] = 9;
193  bitmapsize[50] = 16;
194  bitmapsize[51] = 15;
195  bitmapsize[52] = 13;
196  bitmapsize[53] = 19;
197  bitmapsize[54] = 18;
198  bitmapsize[55] = 11;
199  bitmapsize[56] = 18;
200  bitmapsize[57] = 18;
201  bitmapsize[72] = 16;
202  bitmapsize[99] = 8;
203  bitmapsize[104] = 11;
204  bitmapsize[107] = 11;
205  bitmapsize[109] = 12;
206  bitmapsize[115] = 10;
207  bitmapsize[122] = 10;
208 
209  hwlib::location b39[] = { //Array of the inch sign.
210  hwlib::location(2, 1), hwlib::location(4, 1),
211  hwlib::location(2, 2), hwlib::location(4, 2)
212  };
213  memcpy(bitmaps[39], b39, 20*sizeof(b39[0]));
214 
215  hwlib::location b45[] = { //Array of minus
216  hwlib::location(2, 3), hwlib::location(3, 3), hwlib::location(4, 3), hwlib::location(5, 3),
217  hwlib::location(2, 4), hwlib::location(3, 4), hwlib::location(4, 4), hwlib::location(5, 4)
218  };
219  memcpy(bitmaps[45], b45, 20*sizeof(b39[0]));
220 
221  hwlib::location b47[] = { //Array of the forward slash
222  hwlib::location(6, 1),
223  hwlib::location(5, 2),
224  hwlib::location(4, 3),
225  hwlib::location(3, 4),
226  hwlib::location(2, 5),
227  hwlib::location(1, 6)
228  };
229  memcpy(bitmaps[47], b47, 20*sizeof(b39[0]));
230 
231  hwlib::location b48[] = { //Array of zero, location 48
232  hwlib::location(3, 1), hwlib::location(4, 1),
233  hwlib::location(2, 2), hwlib::location(5, 2),
234  hwlib::location(1, 3), hwlib::location(6, 3),
235  hwlib::location(1, 4), hwlib::location(6, 4),
236  hwlib::location(2, 5), hwlib::location(5, 5),
237  hwlib::location(3, 6), hwlib::location(4, 6)
238  };
239  memcpy(bitmaps[48], b48, 20*sizeof(b39[0]));
240 
241  hwlib::location b49[] = { //Array of one
242  hwlib::location(2, 1),
243  hwlib::location(1, 2), hwlib::location(2, 2),
244  hwlib::location(2, 3),
245  hwlib::location(2, 4),
246  hwlib::location(2, 5),
247  hwlib::location(1, 6), hwlib::location(2, 6), hwlib::location(3, 6)
248  };
249  memcpy(bitmaps[49], b49, 20*sizeof(b39[0]));
250 
251  hwlib::location b50[] = { //Array of two
252  hwlib::location(2, 1), hwlib::location(3, 1), hwlib::location(4, 1), hwlib::location(5, 1),
253  hwlib::location(1, 2), hwlib::location(6, 2),
254  hwlib::location(5, 3),
255  hwlib::location(3, 4), hwlib::location(4, 4),
256  hwlib::location(2, 5),
257  hwlib::location(1, 6), hwlib::location(2, 6), hwlib::location(3, 6), hwlib::location(4, 6), hwlib::location(5, 6), hwlib::location(6, 6)
258  };
259  memcpy(bitmaps[50], b50, 20*sizeof(b39[0]));
260 
261  hwlib::location b51[] = { //Array of three
262  hwlib::location(2, 1), hwlib::location(3, 1), hwlib::location(4, 1), hwlib::location(5, 1),
263  hwlib::location(1, 2), hwlib::location(6, 2),
264  hwlib::location(5, 3),
265  hwlib::location(3, 4), hwlib::location(4, 4),
266  hwlib::location(1, 5), hwlib::location(6, 5),
267  hwlib::location(2, 6), hwlib::location(3, 6), hwlib::location(4, 6), hwlib::location(5, 6)
268  };
269  memcpy(bitmaps[51], b51, 20*sizeof(b39[0]));
270 
271  hwlib::location b52[] = { //Array of four
272  hwlib::location(4, 1),
273  hwlib::location(3, 2), hwlib::location(4, 2),
274  hwlib::location(2, 3), hwlib::location(4, 3),
275  hwlib::location(1, 4), hwlib::location(4, 4),
276  hwlib::location(1, 5), hwlib::location(2, 5), hwlib::location(3, 5), hwlib::location(4, 5), hwlib::location(5, 5),
277  hwlib::location(4, 6)
278  };
279  memcpy(bitmaps[52], b52, 20*sizeof(b39[0]));
280 
281  hwlib::location b53[] = { //Array of five
282  hwlib::location(1, 1), hwlib::location(2, 1), hwlib::location(3, 1), hwlib::location(4, 1), hwlib::location(5, 1), hwlib::location(6,6),
283  hwlib::location(1, 2),
284  hwlib::location(1, 3), hwlib::location(2, 3), hwlib::location(3, 3), hwlib::location(4, 3), hwlib::location(5, 3),
285  hwlib::location(6, 4),
286  hwlib::location(1, 5), hwlib::location(6, 5),
287  hwlib::location(2, 6), hwlib::location(3, 6), hwlib::location(4, 6), hwlib::location(5, 6)
288  };
289  memcpy(bitmaps[53], b53, 20*sizeof(b39[0]));
290 
291  hwlib::location b54[] = { //Array of six
292  hwlib::location(2, 1), hwlib::location(3, 1), hwlib::location(4, 1), hwlib::location(5, 1),
293  hwlib::location(1, 2),
294  hwlib::location(1, 3), hwlib::location(2, 3), hwlib::location(3, 3), hwlib::location(4, 3), hwlib::location(5, 3),
295  hwlib::location(1, 4), hwlib::location(6, 4),
296  hwlib::location(1, 5), hwlib::location(6, 5),
297  hwlib::location(2, 6), hwlib::location(3, 6), hwlib::location(4, 6), hwlib::location(5, 6)
298  };
299  memcpy(bitmaps[54], b54, 20*sizeof(b39[0]));
300 
301  hwlib::location b55[] = { //Array of seven
302  hwlib::location(1, 1), hwlib::location(2, 1), hwlib::location(3, 1), hwlib::location(4, 1), hwlib::location(5, 1), hwlib::location(6, 1),
303  hwlib::location(5, 2),
304  hwlib::location(4, 3),
305  hwlib::location(3, 4),
306  hwlib::location(2, 5),
307  hwlib::location(1, 6)
308  };
309  memcpy(bitmaps[55], b55, 20*sizeof(b39[0]));
310 
311  hwlib::location b56[] = { //Array of eight
312  hwlib::location(2, 6), hwlib::location(3, 6), hwlib::location(4, 6), hwlib::location(5, 6),
313  hwlib::location(1, 5), hwlib::location(6, 5),
314  hwlib::location(2, 4), hwlib::location(3, 4), hwlib::location(4, 4), hwlib::location(5, 4),
315  hwlib::location(1, 3), hwlib::location(6, 3),
316  hwlib::location(1, 2), hwlib::location(6, 2),
317  hwlib::location(2, 1), hwlib::location(3, 1), hwlib::location(4, 1), hwlib::location(5, 1)
318  };
319  memcpy(bitmaps[56], b56, 20*sizeof(b39[0]));
320 
321  hwlib::location b57[] = { //Array of nine, location 57
322  hwlib::location(2, 1), hwlib::location(3, 1), hwlib::location(4, 1), hwlib::location(5, 1),
323  hwlib::location(1, 2), hwlib::location(6, 2),
324  hwlib::location(1, 3), hwlib::location(6, 3),
325  hwlib::location(2, 4), hwlib::location(3, 4), hwlib::location(4, 4), hwlib::location(5, 4), hwlib::location(6, 4),
326  hwlib::location(6, 5),
327  hwlib::location(2, 6), hwlib::location(3, 6), hwlib::location(4, 6), hwlib::location(5, 6)
328  };
329  memcpy(bitmaps[57], b57, 20*sizeof(b39[0]));
330 
331  hwlib::location b72[] = { //Array of the letter "H"
332  hwlib::location(1, 1), hwlib::location(6, 1),
333  hwlib::location(1, 2), hwlib::location(6, 2),
334  hwlib::location(1, 3), hwlib::location(2, 3), hwlib::location(3, 3), hwlib::location(4, 3), hwlib::location(5, 3), hwlib::location(6, 3),
335  hwlib::location(1, 4), hwlib::location(6, 4),
336  hwlib::location(1, 5), hwlib::location(6, 5),
337  hwlib::location(1, 6), hwlib::location(6, 6)
338  };
339  memcpy(bitmaps[72], b72, 20*sizeof(b39[0]));
340 
341  hwlib::location b99[] = { //Array of the letter "c", only 4 in length
342  hwlib::location(2, 3), hwlib::location(3, 3), hwlib::location(4, 3),
343  hwlib::location(1, 4),
344  hwlib::location(1, 5),
345  hwlib::location(2, 6), hwlib::location(3, 6), hwlib::location(4, 6)
346  };
347  memcpy(bitmaps[99], b99, 20*sizeof(b39[0]));
348 
349  hwlib::location b104[] = { //Array of the letter "h", only 4 in length
350  hwlib::location(1, 1),
351  hwlib::location(1, 2),
352  hwlib::location(1, 3), hwlib::location(2, 3), hwlib::location(3, 3),
353  hwlib::location(1, 4), hwlib::location(4, 4),
354  hwlib::location(1, 5), hwlib::location(4, 5),
355  hwlib::location(1, 6), hwlib::location(4, 6)
356  };
357  memcpy(bitmaps[104], b104, 20*sizeof(b39[0]));
358 
359  hwlib::location b107[] = { //Array of the letter "k", only 4 in length
360  hwlib::location(1, 1),
361  hwlib::location(1, 2),
362  hwlib::location(1, 3), hwlib::location(4, 3),
363  hwlib::location(1, 4), hwlib::location(3, 4),
364  hwlib::location(1, 5), hwlib::location(2, 5),
365  hwlib::location(1, 6), hwlib::location(3, 6), hwlib::location(4, 6)
366  };
367  memcpy(bitmaps[107], b107, 20*sizeof(b39[0]));
368 
369  hwlib::location b109[] = { //Array of the letter "m"
370  hwlib::location(1, 3), hwlib::location(2, 3), hwlib::location(5, 3), hwlib::location(6, 3),
371  hwlib::location(1, 4), hwlib::location(3, 4), hwlib::location(4, 4), hwlib::location(6, 4),
372  hwlib::location(1, 5), hwlib::location(6, 5),
373  hwlib::location(1, 6), hwlib::location(6, 6)
374  };
375  memcpy(bitmaps[109], b109, 20*sizeof(b39[0]));
376 
377  hwlib::location b115[] = { //Array of the letter "s", only 4 in length.
378  hwlib::location(2, 2), hwlib::location(3, 2), hwlib::location(4, 2),
379  hwlib::location(1, 3),
380  hwlib::location(2, 4), hwlib::location(3, 4),
381  hwlib::location(3, 5),
382  hwlib::location(1, 6), hwlib::location(2, 6), hwlib::location(3, 6)
383  };
384  memcpy(bitmaps[115], b115, 20*sizeof(b39[0]));
385 
386  hwlib::location b122[] = { //Array of the letter 'z'.
387  hwlib::location(1, 3), hwlib::location(2, 3), hwlib::location(3, 3), hwlib::location(4, 3),
388  hwlib::location(3, 4),
389  hwlib::location(2, 5),
390  hwlib::location(1, 6), hwlib::location(2, 6), hwlib::location(3, 6), hwlib::location(4, 6),
391  };
392  memcpy(bitmaps[122], b122, 20*sizeof(b39[0]));
393  }
394 
396  int getSize(char c) {
397  int value = c;
398  return bitmapsize[value];
399  }
400 };
401 
403 class display {
404 private:
405  hwlib::window & w;
406 public:
407  display(hwlib::window & w):
408  w(w)
409  {}
410 
412  //
415  void dispPerc(int perc, int width) {
416  w.clear();
417  for (int i = 1; i < ((41*width)/64); i++) {
418  for (int j = 1; j < ((perc*164)/128); j++) {
419  w.write(hwlib::location(j,i), hwlib::black);
420  }
421  }
422  }
423 
424 
426  //
429  void dispNumber(int number, int height) {
430  disparray arrays;
431  hwlib::location heightcorr(0, 29+height);
432  if (number == 0) {
433  for (int i = 0; i < arrays.getSize('0'); i++) {
434  w.write(arrays.bitmaps['0'][i] + heightcorr, hwlib::black);
435  }
436  return;
437  }
438  int digits = 0;
439  bool neg = 0;
440  int a[4] = { 0,0,0,0 };
441  if (number < 0) {
442  neg = 1;
443  number *= -1;
444  }
445  if ((number / 1000) > 0) {
446  a[3] = number % 10;
447  number /= 10;
448  a[2] = number % 10;
449  number /= 10;
450  a[1] = number % 10;
451  number /= 10;
452  a[0] = number;
453  digits = 4;
454  }
455  else if ((number / 100) > 0) {
456  a[2] = number % 10;
457  number /= 10;
458  a[1] = number % 10;
459  number /= 10;
460  a[0] = number;
461  digits = 3;
462  }
463  else if ((number / 10) > 0) {
464  a[1] = number % 10;
465  number /= 10;
466  a[0] = number;
467  digits = 2;
468  }
469  else {
470  a[0] = number;
471  digits = 1;
472  }
473  int xcorrection = 0;
474  if (neg) {
475  for (int i = 0; i < arrays.getSize('-'); i++) {
476  w.write(arrays.bitmaps['-'][i] + heightcorr, hwlib::black);
477  }
478  xcorrection += 8;
479  }
480  for (int i = 0; i < digits; i++) {
481  for (int j = 0; j < arrays.getSize(a[i] + '0'); j++) {
482  w.write(arrays.bitmaps[a[i] + '0'][j] + heightcorr + hwlib::location(xcorrection, 0), hwlib::black);
483  }
484  xcorrection += 8;
485  }
486  }
487 
488 
490  //
496  void dispNumberUnit(int number, char unit[], int height) {
497  disparray arrays;
498  hwlib::location heightcorr(0, 29+height);
499  bool zero = 0;
500  if (number == 0) {
501  zero = 1;
502  }
503  int digits = 0;
504  bool neg = 0;
505  int a[4] = { 0,0,0,0 };
506  if (number < 0) {
507  neg = 1;
508  number *= -1;
509  }
510  if ((number / 1000) > 0) {
511  a[3] = number % 10;
512  number /= 10;
513  a[2] = number % 10;
514  number /= 10;
515  a[1] = number % 10;
516  number /= 10;
517  a[0] = number;
518  digits = 4;
519  }
520  else if ((number / 100) > 0) {
521  a[2] = number % 10;
522  number /= 10;
523  a[1] = number % 10;
524  number /= 10;
525  a[0] = number;
526  digits = 3;
527  }
528  else if ((number / 10) > 0) {
529  a[1] = number % 10;
530  number /= 10;
531  a[0] = number;
532  digits = 2;
533  }
534  else {
535  a[0] = number;
536  digits = 1;
537  }
538  int xcorrection = 0;
539  if (neg) {
540  for (int i = 0; i < arrays.getSize('-'); i++) {
541  w.write(arrays.bitmaps['-'][i] + heightcorr, hwlib::black);
542  }
543  xcorrection += 8;
544  }
545  if (!zero) {
546  for (int i = 0; i < digits; i++) {
547  for (int j = 0; j < arrays.getSize(a[i] + '0'); j++) {
548  w.write(arrays.bitmaps[a[i] + '0'][j] + heightcorr + hwlib::location(xcorrection, 0), hwlib::black);
549  }
550  xcorrection += 8;
551  }
552  }
553  else {
554  for (int i = 0; i < arrays.getSize('0'); i++) {
555  w.write(arrays.bitmaps['0'][i] + heightcorr, hwlib::black);
556  }
557  xcorrection += 8;
558  }
559  xcorrection += 2;
560 
561  for (int i = 0; unit[i] != '\0'; i++) {
562  for (int j = 0; j < arrays.getSize(unit[i]); j++) {
563  int character = unit[i];
564  w.write(arrays.bitmaps[character][j] + heightcorr + hwlib::location(xcorrection, 0), hwlib::black);
565  }
566  xcorrection += 8;
567  }
568  }
569 };
570 
572 //
574 class controller {
575 protected:
576  display & screen;
577 public:
579  controller(display & screen):
580  screen(screen) {}
581 
583  //
585  virtual int getResult(Unit unit) = 0;
586 
588  //
590  virtual void dispResult(Unit unit, int height) = 0;
591 
592 };
593 
595 //
597 class contrDist : public controller {
598 private:
599  distancemeter & meter;
600 public:
601  contrDist(distancemeter & meter, display & screen):
602  controller(screen), meter(meter) {}
603 
605  //
610 
611  int getResult(Unit unit) {
612  return meter.measure(unit);
613  }
614 
616  //
621  void dispResult(Unit unit, int height) {
622  int result = meter.measure(unit);
623  if (result > 1000) {
624  hwlib::cout << "WARNING: Inaccurate measurement detected!\n";
625  result = 0;
626  }
627  switch(unit) {
628  case Unit::Centim : screen.dispNumberUnit(result, (char*)"cm", height); return;
629  case Unit::Inch : screen.dispNumberUnit(result, (char*)"\'", height); return;
630  default : hwlib::cout << "ERROR: Entered unit not available in this function\n"; return;
631  }
632  }
633 };
634 
636 class contrSpeed : public controller {
637 private:
638  speedometer & meter;
639  int delay = 10;
640 public:
641  contrSpeed(speedometer & meter, display & screen):
642  controller(screen), meter(meter) {}
643 
645  //
652  int getResult(Unit unit) {
653  return meter.getSpeed(unit, delay);
654  }
655 
657  //
665  void dispResult(Unit unit, int height) {
666  int result = meter.getSpeed(unit, delay);
667  switch(unit) {
668  case Unit::Cms : screen.dispNumberUnit(result, (char*)"cm/s", height); return;
669  case Unit::Kmh : screen.dispNumberUnit(result, (char*)"km/h", height); return;
670  case Unit::Mh : screen.dispNumberUnit(result, (char*)"m/h", height); return;
671  case Unit::Ms : screen.dispNumberUnit(result, (char*)"m/s", height); return;
672  default : hwlib::cout << "ERROR: Entered unit not available in this function\n"; return;
673  }
674  }
675 
676 
678  //
680  void setDelay(int pdelay) {
681  delay = pdelay;
682  }
683 };
684 
686 class contrFreq : public controller {
687 private:
688  speedometer & meter;
689  int delay1 = 100;
690  int delay2 = 10;
691  int measurements = 50;
692 public:
693  contrFreq(speedometer & meter, display & screen):
694  controller(screen), meter(meter) {}
695 
697  //
703  int getResult(Unit unit) {
704  return meter.getFreq(measurements, unit, delay1, delay2);
705  }
706 
708  //
714  void dispResult(Unit unit, int height) {
715  int result = meter.getFreq(measurements, unit, delay1, delay2);
716  switch(unit) {
717  case Unit::Hz : screen.dispNumberUnit(result, (char*)"Hz", height); return;
718  case Unit::mHz : screen.dispNumberUnit(result, (char*)"mHz", height); return;
719  default : hwlib::cout << "ERROR: Entered unit not available in this function\n"; return;
720  }
721  }
722 
724  void setDelay1 (int delay) {
725  delay1 = delay;
726  }
727 
729  void setDelay2 (int delay) {
730  delay2 = delay;
731  }
732 
734  void setMeasurements (int mes) {
735  measurements = mes;
736  }
737 };
738 
739 
740 #endif // HCSR04
hcsr04(hwlib::target::pin_out &trig, hwlib::target::pin_in &echo)
Constructor which has two pins as parameters, trig output pin and echo input pin. ...
Definition: HCSR04.h:73
Controller superclass.
Definition: HCSR04.h:574
void setDelay1(int delay)
Function for setting the delay between getSpeed() calls.
Definition: HCSR04.h:724
Sub-class for distance sensor HCSR04 which is a sonar based distance sensor.
Definition: HCSR04.h:66
int getFreq(int measurements, Unit unit=Unit::Hz, int delay1=10, int delay2=100)
Calculates the frequency of a moving object.
Definition: HCSR04.h:150
distancemeter()
Empty constuctor.
Definition: HCSR04.h:53
int getResult(Unit unit)
Function for fetching result.
Definition: HCSR04.h:652
Class solely for storing the character bitmaps, and information about these character bitmaps...
Definition: HCSR04.h:180
void dispResult(Unit unit, int height)
Function for displaying result directly on display.
Definition: HCSR04.h:621
int getResult(Unit unit)
Function for fetching result.
Definition: HCSR04.h:611
Abstract class which is able to measure distance.
Definition: HCSR04.h:50
void dispResult(Unit unit, int height)
Function for displaying result directly on display.
Definition: HCSR04.h:665
void setDelay(int pdelay)
Function for setting the delay between the two distance measurements inside getSpeed().
Definition: HCSR04.h:680
void dispNumber(int number, int height)
This function displays an integer on the display.
Definition: HCSR04.h:429
Unit
Units used in distancemeter and speedometer.
Definition: HCSR04.h:47
void dispResult(Unit unit, int height)
Function for displaying result directly on display.
Definition: HCSR04.h:714
Speedometer controller.
Definition: HCSR04.h:636
void dispNumberUnit(int number, char unit[], int height)
This function displays a number and a unit. .
Definition: HCSR04.h:496
void setDelay2(int delay)
Function for setting the delay inside the getSpeed() function, between the two distance measurements...
Definition: HCSR04.h:729
int getResult(Unit unit)
Function for fetching result..
Definition: HCSR04.h:703
controller(display &screen)
Superclass constructor.
Definition: HCSR04.h:579
long long int getSpeed(Unit unit=Unit::Ms, int delay=10)
Calculates the speed of a moving object.
Definition: HCSR04.h:127
void setMeasurements(int mes)
Function for setting the amount of times getSpeed() is called during getResult() or dispResult()...
Definition: HCSR04.h:734
long long int measure(Unit unit=Unit::Centim)
Distance measurement function for the HCSR04 sonar distance sensor.
Definition: HCSR04.h:79
Class which can create objects which can calculate speed. Requires object distance sensor...
Definition: HCSR04.h:103
Class for displaying certain data on a display.
Definition: HCSR04.h:403
Frequency meter controller.
Definition: HCSR04.h:686
virtual long long int measure(Unit unit=Unit::Centim)=0
Virtual function which returns the distance from the sensor to an object in unit defined in parameter...
Distance meter controller.
Definition: HCSR04.h:597
void dispPerc(int perc, int width)
Function which display a percentage in the form of a percentage bar in horizontal direction...
Definition: HCSR04.h:415
int getSize(char c)
Function for requesting the bitmap size of a certain character.
Definition: HCSR04.h:396