Skip to content

Instantly share code, notes, and snippets.

@yzdann
Last active December 29, 2019 07:48
Show Gist options
  • Save yzdann/c87a1d59aed7774f4461f70a76c177d2 to your computer and use it in GitHub Desktop.
Save yzdann/c87a1d59aed7774f4461f70a76c177d2 to your computer and use it in GitHub Desktop.
#include "LiquidCrystal.h"
#include "Timer.h"
Timer Count;
// rs, en, d4, d5, d6, d7
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
long rpmcount;
const int hallPin = 2;
int time_now = 0;
void setup()
{
pinMode(hallPin,INPUT);
lcd.begin(16, 2);
lcd.print("RPM: ");
lcd.setCursor(0,1);
attachInterrupt(digitalPinToInterrupt(hallPin), rpmFunc, RISING);
Count.every(5000, rpmCal);
}
void loop() {
Count.update();
}
void rpmCal() {
lcd.print(rpmcount*2*5);
delay(1000);
rpmcount = 0;
clearLCDLine(1);
}
void rpmFunc()
{
rpmcount++;
}
void clearLCDLine(int line){
for(int n = 0; n < 12; n++) {
lcd.setCursor(n,line);
lcd.print(" ");
}
lcd.setCursor(0,line);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment