Created
October 22, 2018 13:35
-
-
Save abdul-rehman-2050/a23fe054bf75a55e22f6367e11081222 to your computer and use it in GitHub Desktop.
Frequency Counter using external interrupt in Arduino Sketch http://www.fypsolutions.com/tutorials/frequency-meter-using-arduino/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// include the library code: | |
#include <LiquidCrystal.h> | |
// initialize the library with the numbers of the interface pins | |
LiquidCrystal lcd(6, 7, 10, 11, 12, 13); | |
int freqCounter = 0; | |
long preMillis = 0; | |
void isr() //interrupt service routine | |
{ | |
freqCounter++; | |
} | |
void printCounting(){ | |
lcd.setCursor(6, 1); //6th column and second row | |
lcd.print((freqCounter/1000)%10); | |
lcd.print((freqCounter/100)%10); | |
lcd.print((freqCounter/10)%10); | |
lcd.print(freqCounter%10); | |
lcd.print("Hz"); | |
} | |
void setup() { | |
// set up the LCD's number of columns and rows: | |
lcd.begin(16, 2); | |
// Print a message to the LCD. | |
lcd.print("Frequency Meter"); | |
printCounting(); | |
delay(10); | |
attachInterrupt(0,isr,RISING); //attaching the interrupt | |
} | |
void loop() { | |
while((millis()-preMillis)<1000); | |
detachInterrupt(0); //detaches the interrupt | |
printCounting(); | |
freqCounter = 0; | |
preMillis = millis(); | |
attachInterrupt(0,isr,RISING); //attaching the interrupt again | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment