#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define sensor 9
#define start 12
int delay1();
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
{
int i,j;
unsigned int count=0;
for(i=0;i<1000;i++)
{
for(j=0;j<1227;j++)
{
if(digitalRead(sensor))
{
count++;
while(digitalRead(sensor));
}
}
}
return count;
}
void setup()
{
Servo myservo;
myservo.attach(6);
pinMode(sensor, INPUT);
pinMode(start, INPUT);
lcd.init();
lcd.backlight();
lcd.setCursor (0,0);
lcd.print (" Activated... ");
delay(1000);
lcd.clear();
lcd.setCursor (0,0);
lcd.print ("Initiating...");
delay (500);
lcd.setCursor (2,3);
lcd.print ("119290081");
delay (700);
lcd.clear();
lcd.print("---Tachometer---");
delay (500);
lcd.setCursor (1,1);
lcd.print ("Welcome Taufik");
delay(1000);
digitalWrite(start, HIGH);
}
void loop()
{
unsigned int time=0,RPM=0;
lcd.clear();
lcd.print(" Please Press ");
lcd.setCursor(1,1);
lcd.print("Button to Start ");
delay (800);
while(digitalRead(start));
lcd.clear();
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
lcd.print("Reading RPM.....");
time=delay1();
lcd.clear();
lcd.print("Please Wait.....");
RPM=(time*12)/3;
delay(2000);
lcd.clear();
lcd.print("RPM=");
lcd.print(RPM);
delay(5000);
}