-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArduinoTachometer.ino.orig
170 lines (154 loc) · 4.48 KB
/
ArduinoTachometer.ino.orig
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
int previousSensorValue = -1;
bool dataCollectionState = false;
bool endDataState = false;
unsigned long dataStartTime = 0;
<<<<<<< HEAD
const int ANALOG_HIGH = 1023;
const int DIGITAL_LIGHT_SENSOR_PIN = 0;
const int ANALOG_BUTTON_OUT_PIN = 1;
const int DIGITAL_INDICATOR_PIN = 2;
=======
const int POWER_LIGHT_SENSOR_PIN = 13;
const int POWER_BUTTON_OUT_PIN = 4;
const int POWER_INDICATOR_PIN = 2;
>>>>>>> 84694ace0bc7fd03174db6dab9aa5555c86066b7
const int TOLERANCE = 1;
/************************************* Main Body **************************************************************/
void setup() {
initializePins();
//Begin sending output at 9600 baud
Serial.begin(9600);
sendCSVHeader();
// On startup, turn sensor off
<<<<<<< HEAD
//setLightSensor(dataCollectionState);
=======
setLightSensor(dataCollectionState);
>>>>>>> 84694ace0bc7fd03174db6dab9aa5555c86066b7
}
void loop() {
// Code here will check for for the start/stop collecting-data event and
// set the power to the LED transistor appropriately (for now, the default is always on)
<<<<<<< HEAD
if (analogRead(ANALOG_BUTTON_OUT_PIN) == ANALOG_HIGH) {
setIndicatorLight(true);
} else {
setIndicatorLight(false);
}
delay(5);
/*
// If we haven't started collecting
if (!dataCollectionState) {
// Check for the button press
Serial.println("dataCollectionState = FALSE");
if (digitalRead(POWER_BUTTON_OUT_PIN) == HIGH) {
// Start light sensor
setLightSensor(true);
//start timer
startDataCollectionTimer();
// set data collection flag
dataCollectionState = true;
}
} else if (!endDataState) {
// check timer
checkTime();
//Read output from Light Sensor and write to serial port
previousSensorValue = writeSensorValue(analogRead(A0));
}
*/
=======
// If we haven't started collecting
if (!dataCollectionState) {
// Check for the button press
if (digitalRead(POWER_BUTTON_OUT_PIN) == HIGH) {
// Start light sensor
setLightSensor(true);
//start timer
startDataCollectionTimer();
// set data collection flag
dataCollectionState = true;
}
} else if (!endDataState) {
// check timer
checkTime();
//Read output from Light Sensor and write to serial port
previousSensorValue = writeSensorValue(analogRead(A0));
}
>>>>>>> 84694ace0bc7fd03174db6dab9aa5555c86066b7
}
/************************************* End Main Body **************************************************************/
void initializePins() {
<<<<<<< HEAD
pinMode(DIGITAL_LIGHT_SENSOR_PIN, OUTPUT);
//pinMode(POWER_BUTTON_OUT_PIN, INPUT);
pinMode(DIGITAL_INDICATOR_PIN, OUTPUT);
=======
pinMode(POWER_LIGHT_SENSOR_PIN, OUTPUT);
pinMode(POWER_BUTTON_OUT_PIN, INPUT);
pinMode(POWER_INDICATOR_PIN, OUTPUT);
>>>>>>> 84694ace0bc7fd03174db6dab9aa5555c86066b7
}
void sendCSVHeader() {
Serial.println("Voltage,Time Of Measurement");
}
void startDataCollectionTimer() {
dataStartTime = millis();
}
bool checkTime() {
if (millis() > dataStartTime + 60000) {
setIndicatorLight(false);
endDataState = true;
return endDataState;
}
return false;
}
void printSensorValue(int sensorValue) {
Serial.print(sensorValue);
Serial.print(",");
Serial.println(micros());
}
void setLightSensor(bool powerState) {
if (powerState) {
if (!endDataState) {
<<<<<<< HEAD
digitalWrite(DIGITAL_LIGHT_SENSOR_PIN, HIGH);
=======
digitalWrite(POWER_LIGHT_SENSOR_PIN, HIGH);
>>>>>>> 84694ace0bc7fd03174db6dab9aa5555c86066b7
dataCollectionState = true;
setIndicatorLight(powerState);
}
} else {
<<<<<<< HEAD
digitalWrite(DIGITAL_LIGHT_SENSOR_PIN, LOW);
=======
digitalWrite(POWER_LIGHT_SENSOR_PIN, LOW);
>>>>>>> 84694ace0bc7fd03174db6dab9aa5555c86066b7
dataCollectionState = false;
}
}
void setIndicatorLight(bool powerState) {
if (powerState) {
<<<<<<< HEAD
digitalWrite(DIGITAL_INDICATOR_PIN, HIGH);
} else {
digitalWrite(DIGITAL_INDICATOR_PIN, LOW);
=======
digitalWrite(POWER_INDICATOR_PIN, HIGH);
} else {
digitalWrite(POWER_INDICATOR_PIN, LOW);
>>>>>>> 84694ace0bc7fd03174db6dab9aa5555c86066b7
}
}
int writeSensorValue(int sensorValue) {
// If the value differs from the previous value by the amount TOLERANCE, print the new value
if ((abs(sensorValue - previousSensorValue)) > TOLERANCE) {
printSensorValue(sensorValue);
} else {
delay(1);
}
return sensorValue;
}
<<<<<<< HEAD
=======
>>>>>>> 84694ace0bc7fd03174db6dab9aa5555c86066b7