-
Notifications
You must be signed in to change notification settings - Fork 0
/
FC51-IRArray.h
46 lines (42 loc) · 965 Bytes
/
FC51-IRArray.h
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
#ifndef IRARRAY_H
#define IRARRAY_H
#include "Arduino.h"
namespace FRC6644 {
template <int N>
class FC51_IRArray{
public:
FC51_IRArray(std::initializer_list<int> ports){
std::initializer_list<int>::iterator it;
auto list_pos = ports.begin();
for(int i = 0; i != size; i++, list_pos++){
sensors[i] = *list_pos;
pinMode(sensors[i], INPUT);
}
}
int getDistances(){
return distances;
}
int getSize(){
return size;
}
void readSensors(){
distances = 0;
for(int i = 0; i != size; i++){
distances |= ((digitalRead(sensors[i]) == LOW) << i);
}
}
void printFormattedIRData(FC51_IRArray array){
int data = array.getDistances();
for(int i = 0; i != array.getSize(); i++){
int value = (data & (1 << i)) >> i;
Serial.println("Sensor " + String(i) + " :" + " " + String(value));
}
Serial.println();
}
private:
int sensors[N];
int distances;
const int size = N;
};
};
#endif