hi,
i would like to add a countdown timer (adjustable from 0-5minutes) to stop spinning my motor.
Can you help me?
Here the code
#include<LiquidCrystal.h>
LiquidCrystal lcd(12,11,6,5,4,3);
int pwm=9;
float value=0;
int percent;
float rev=0;
int rpm;
int oldtime=0;
int time;
void isr() //interrupt service routine
{
rev++;
}
void setup()
{
lcd.begin(16,2); //initialize LCD
attachInterrupt(0,isr,RISING); //attaching the interrupt
}
void loop()
{
delay(3000);
detachInterrupt(0); //detaches the interrupt
time=millis()-oldtime; //finds the time
rpm=(rev/time)*60000/2; //calculates rpm
oldtime=millis(); //saves the current time
rev=0;
value=55;
analogWrite(pwm,value); //sets the desired speed
percent=(value/255)*100;//finds the duty cycle %
lcd.clear();
lcd.setCursor(1,0);
lcd.print("TACHOMETER_");
lcd.setCursor(0,1);
lcd.print(rpm);
lcd.print(" RPM");
lcd.print(" ");
lcd.print(percent);
lcd.print("%");
lcd.print(" ");
lcd.print("S.P");
attachInterrupt(0,isr,RISING);
}
Or, more complex, can we add ramp function(i.e value=55, delay(3000), value=255, delay(6000)) and stop spinning
Thank's a lot