float tiempo1;
float tiempo2;
float rpm;
volatile unsigned pulso=0;
int conta1=0;// aux para promedio
volatile float conta2=0; // aux para promedio
int led=13;
int MOSFET = 11; // pin salida pwm
int Sensor = A0; //potenciometro
volatile int lectura=0; // guarda el valor del potenciometro;
void setup(){
Serial.begin(57600) ;
pinMode(13,led);
pinMode(2,INPUT);
pinMode(MOSFET, OUTPUT);
attachInterrupt(0,TICK,RISING);
tiempo2 = 0;
}
void loop()
{
lectura = analogRead(Sensor);
lectura = map(lectura, 0, 1023, 0, 100);
Serial.println( lectura);
if(pulso==8) //8 aspas
{
detachInterrupt(0);
pulso=0;
tiempo1 = tiempo2;
tiempo2 = micros() ;
rpm = 60000000.0/(tiempo2 - tiempo1);//60 segundos por 1 millon
// promedio*****************
conta1++;
conta2=rpm+conta2;
if (conta1==5)
{
Serial.println(conta2/5);
conta1=0;
conta2=0;
}
// fin promedio*****************
attachInterrupt(0,TICK,RISING);
}
}
void TICK()
{
pulso++;
}