-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNapon_ACC.ino
51 lines (38 loc) · 1.34 KB
/
Napon_ACC.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
const int numReadings = 500;
int readings[numReadings]; // the readings from the analog input
long readIndex = 0; // the index of the current reading
long total = 0; // the running total
long average = 0; // the average
int inputPin = A8;
void napon_ACC_setup() {
// initialize all the readings to 0:
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
readings[thisReading] = 0;
}
}
void napon_ACC_loop() {
while(true){
// subtract the last reading:
total = total - readings[readIndex];
// read from the sensor:
readings[readIndex] = analogRead(inputPin);
// add the reading to the total:
total = total + readings[readIndex];
// advance to the next position in the array:
readIndex = readIndex + 1;
// if we're at the end of the array...
if (readIndex >= numReadings) {
// ...wrap around to the beginning:
readIndex = 0;
// calculate the average:
average = total / numReadings;
voltage_acc = average * (5.0 / 1023.0)*3.86645;
Serial.print("Napon na ACC: ");
Serial.print(voltage_acc);
Serial.println(" V");
Serial.println(" ");
break;
}
delay(1); // delay in between reads for stability
}
}