-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiv-zero.ino
158 lines (139 loc) · 3.03 KB
/
iv-zero.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
#include "setup.h"
#include "function_voltage.h"
#include "function_temperature.h"
#include "function_tds18b20.h"
#include "function_pressure.h"
uint8_t timeCount = 0;
uint32_t LEDs_set;
#ifdef STROBE
ISR(TIMER1_COMPA_vect) //Timer 0 overflow vector - this run every time timer0 overflows
{
timeCount++;
if(timeCount > DUTY_CYCLE) //Timer overflown for the 61th time
{
for (int i=0;i!=DEVICE_LED_COUNT;i++)
{
digitalWrite(LEDs[i], (LEDs_set & (1<<i)) ? HIGH : LOW);
}
}
else
{
for (int i=0;i!=DEVICE_LED_COUNT;i++)
{
digitalWrite(LEDs[i], LOW);
}
}
}
#endif
void setup() {
LEDs_set=0;
//If we need a startup blink with max intensity:
#ifdef START_BLINK
for (int i=0;i!=LEDs_count;i++)
{
pinMode(LEDs[i],OUTPUT);
digitalWrite(LEDs[i], HIGH);
}
delay(100);
for (int i=0;i!=LEDs_count;i++)
{
digitalWrite(LEDs[i], LOW);
}
#else
for (int i=0;i!=LEDs_count;i++)
{
pinMode(LEDs[i],OUTPUT);
}
#endif
analogReference(0);
//PWM Brightness
#ifdef STROBE
cli(); // stop interrupts
TCCR1A = 0; // set entire TCCR1A register to 0
TCCR1B = 0; // same for TCCR1B
TCNT1 = 0; // initialize counter value to 0
// set compare match register for 1000 Hz increments
OCR1A = 159; // = 16000000 / (1 * 1000) - 1 (must be <65536)
// turn on CTC mode
TCCR1B |= (1 << WGM12);
// Set CS12, CS11 and CS10 bits for 1 prescaler
TCCR1B |= (0 << CS12) | (0 << CS11) | (1 << CS10);
// enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
sei(); // allow interrupts
#endif
#ifdef STROBE
LEDs_set = 0xFFF;
delay(100);
LEDs_set = 0x0;
delay(100);
#endif
}
void loop()
{
#ifndef TESTMODE
uint8_t leds_lit = 0;
//Voltmeter
#ifdef FUNCTION_VOLTAGE
uint16_t adc_res=0;
for (int i=0;i!=16;i++)
{
adc_res+=analogRead(analogPin);
}
adc_res=adc_res>>4; // div by 16
leds_lit = countLedsLitVoltage(adc_res);
#endif
#ifdef FUNCTION_PRESSURE
uint16_t adc_res=0;
for (int i=0;i!=16;i++)
{
adc_res+=analogRead(analogPin);
}
adc_res=adc_res>>4; // div by 16
leds_lit = countLedsLitPressure(adc_res);
#endif
//Temperature sensor
#if defined (FUNCTION_TEMPERATURE) || defined(FUNCTION_TEMPERATURE_DS18B20)
processOilTemperature();
leds_lit = countLedsLitTemperature();
#endif
leds_lit = constrain(leds_lit,0,DEVICE_LED_COUNT);
//Set LEDs active
for (int i=0;i!=leds_lit;i++)
{
#ifndef STROBE
digitalWrite(LEDs[i], HIGH);
#else
LEDs_set|=(1<<i);
#endif
}
//Reset LEDs which are not active
for (int i=leds_lit;i!=DEVICE_LED_COUNT;i++)
{
#ifndef STROBE
digitalWrite(LEDs[i], LOW);
#else
LEDs_set&=~(1<<i);
#endif
}
#else
for (int i=0;i!=DEVICE_LED_COUNT;i++)
{
#ifndef STROBE
digitalWrite(LEDs[i], HIGH);
#else
LEDs_set|=(1<<i);
#endif
delay(300);
}
for (int i=0;i!=DEVICE_LED_COUNT;i++)
{
#ifndef STROBE
digitalWrite(LEDs[i], LOW);
#else
LEDs_set&=~(1<<i);
#endif
delay(300);
}
#endif
}