-
Notifications
You must be signed in to change notification settings - Fork 7
/
Easytimer.h
46 lines (40 loc) · 1.1 KB
/
Easytimer.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
//Credit to airbirds.de and polyvision UG for coming up with the original easyracelaptimer system!
#define BIT_SET(a,b) ((a) |= (1<<(b)))
#define BIT_CLEAR(a,b) ((a) &= ~(1<<(b)))
#define BIT_FLIP(a,b) ((a) ^= (1<<(b)))
#define BIT_CHECK(a,b) ((a) & (1<<(b)))
#define NUM_BITS 9
#define ZERO 250
#define ONE 650
unsigned int buffer[NUM_BITS];
unsigned int num_one_pulses = 0;
unsigned int get_pulse_width_for_buffer(int bit){
if(BIT_CHECK(easylap_id,bit)){
return ONE;
}
return ZERO;
}
unsigned int control_bit(){
if(num_one_pulses % 2 >= 1){
return ONE;
}else{
return ZERO;
}
}
void geteasylapcode() {
buffer[0] = ZERO;
buffer[1] = ZERO;
buffer[2] = get_pulse_width_for_buffer(5);
buffer[3] = get_pulse_width_for_buffer(4);
buffer[4] = get_pulse_width_for_buffer(3);
buffer[5] = get_pulse_width_for_buffer(2);
buffer[6] = get_pulse_width_for_buffer(1);
buffer[7] = get_pulse_width_for_buffer(0);
buffer[8] = control_bit();
#ifdef debug
for(int i= 0; i < NUM_BITS; i++){
Serial.println(buffer[i],DEC);
}
Serial.println(easylap_id,BIN);
#endif
}