LOL! What sketch? That would seem to be pertinent to any sort of discussion. Wouldn't it? :o
The sketch;
// read RPM
volatile int rpmcount = 0;//see http://arduino.cc/en/Reference/Volatile
int rpm = 0;
unsigned long lastmillis = 0;
void setup(){
Serial.begin(9600);
attachInterrupt(0, rpm_fan, FALLING);//interrupt cero (0) is on pin two(2).
}
void loop(){
if (millis() - lastmillis == 1000){ /*Uptade every one second, this will be equal to reading frecuency (Hz).*/
detachInterrupt(0); //Disable interrupt when calculating
rpm = rpmcount * 60; /* Convert frecuency to RPM, note: this works for one interruption per full rotation. For two interrups per full rotation use rpmcount * 30.*/
Serial.print("RPM =\t"); //print the word "RPM" and tab.
Serial.print(rpm); // print the rpm value.
Serial.print("\t Hz=\t"); //print the word "Hz".
Serial.println(rpmcount); /*print revolutions per second or Hz. And print new line or enter.*/
rpmcount = 0; // Restart the RPM counter
lastmillis = millis(); // Uptade lasmillis
attachInterrupt(0, rpm_fan, FALLING); //enable interrupt
}
}
void rpm_fan(){ /* this code will be executed every time the interrupt 0 (pin2) gets low.*/
rpmcount++;
}
// Elimelec Lopez - April 25th 2013
// read RPM and calculate average every then readings.
const int numreadings = 10;
int readings[numreadings];
unsigned long average = 0;
int index = 0;
unsigned long total;
volatile int rpmcount = 0;//see http://arduino.cc/en/Reference/Volatile
unsigned long rpm = 0;
unsigned long lastmillis = 0;
void setup(){
Serial.begin(9600);
attachInterrupt(0, rpm_fan, FALLING);
}
void loop(){
if (millis() - lastmillis >= 1000){ /*Uptade every one second, this will be equal to reading frecuency (Hz).*/
detachInterrupt(0); //Disable interrupt when calculating
total = 0;
readings[index] = rpmcount * 60; /* Convert frecuency to RPM, note: this works for one interruption per full rotation. For two interrups per full rotation use rpmcount * 30.*/
for (int x=0; x<=9; x++){
total = total + readings[x];
}
average = total / numreadings;
rpm = average;
rpmcount = 0; // Restart the RPM counter
index++;
if(index >= numreadings){
index=0;
}
if (millis() > 11000){ // wait for RPMs average to get stable
Serial.print(" RPM = ");
Serial.println(rpm);
}
lastmillis = millis(); // Uptade lasmillis
attachInterrupt(0, rpm_fan, FALLING); //enable interrupt
}
}
void rpm_fan(){ /* this code will be executed every time the interrupt 0 (pin2) gets low.*/
rpmcount++;
}
And the error message again;
Arduino: 1.8.5 (Windows 8.1), Board: "Arduino/Genuino Uno"
sketch_nov11a:44: error: redefinition of 'volatile int rpmcount'
volatile int rpmcount = 0;//see http://arduino.cc/en/Reference/Volatile
^
C:\Users\Bill\AppData\Local\Temp\arduino_modified_sketch_928984\sketch_nov11a.ino:3:14: note: 'volatile int rpmcount' previously defined here
volatile int rpmcount = 0;//see http://arduino.cc/en/Reference/Volatile
^
sketch_nov11a:45: error: conflicting declaration 'long unsigned int rpm'
unsigned long rpm = 0;
^
C:\Users\Bill\AppData\Local\Temp\arduino_modified_sketch_928984\sketch_nov11a.ino:4:5: note: previous declaration as 'int rpm'
int rpm = 0;
^
sketch_nov11a:46: error: redefinition of 'long unsigned int lastmillis'
unsigned long lastmillis = 0;
^
C:\Users\Bill\AppData\Local\Temp\arduino_modified_sketch_928984\sketch_nov11a.ino:5:15: note: 'long unsigned int lastmillis' previously defined here
unsigned long lastmillis = 0;
^
C:\Users\Bill\AppData\Local\Temp\arduino_modified_sketch_928984\sketch_nov11a.ino: In function 'void setup()':
sketch_nov11a:48: error: redefinition of 'void setup()'
void setup(){
^
C:\Users\Bill\AppData\Local\Temp\arduino_modified_sketch_928984\sketch_nov11a.ino:7:6: note: 'void setup()' previously defined here
void setup(){
^
C:\Users\Bill\AppData\Local\Temp\arduino_modified_sketch_928984\sketch_nov11a.ino: In function 'void loop()':
sketch_nov11a:53: error: redefinition of 'void loop()'
void loop(){
^
C:\Users\Bill\AppData\Local\Temp\arduino_modified_sketch_928984\sketch_nov11a.ino:12:6: note: 'void loop()' previously defined here
void loop(){
^
C:\Users\Bill\AppData\Local\Temp\arduino_modified_sketch_928984\sketch_nov11a.ino: In function 'void rpm_fan()':
sketch_nov11a:88: error: redefinition of 'void rpm_fan()'
void rpm_fan(){ /* this code will be executed every time the interrupt 0 (pin2) gets low.*/
^
C:\Users\Bill\AppData\Local\Temp\arduino_modified_sketch_928984\sketch_nov11a.ino:33:6: note: 'void rpm_fan()' previously defined here
void rpm_fan(){ /* this code will be executed every time the interrupt 0 (pin2) gets low.*/
^
exit status 1
redefinition of 'volatile int rpmcount'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.