Advertisement
tiodocomputador

Frequencimetro simples

Jun 8th, 2014
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. #include <Wire.h>
  3. LiquidCrystal lcd(8, 9, 4, 5, 6, 7);   //Use estes valores quando trabalhar na protoboard
  4. //LiquidCrystal lcd(13, 12, 11, 10, 9, 8);   //Use estes valores quando trabalhar no proteus
  5. const int entrada = 2;
  6.  
  7.  
  8. void setup()
  9. {  
  10.   Serial.begin(9600);
  11.   pinMode(entrada, INPUT);
  12.   lcd.begin(20, 2);
  13. }
  14.  
  15. void loop()
  16. {
  17.   int t=500;
  18.   unsigned long pico  = 0;
  19.   unsigned long vale = 0;
  20. float periodo = 0;
  21. float frequencia = 0;
  22.  
  23.   pico    = (pulseIn(entrada, HIGH));
  24.   vale   = (pulseIn(entrada, LOW));
  25.   periodo = (pico + vale);
  26.   frequencia = (1000000/periodo);
  27.  
  28.   if(periodo)
  29.   {
  30.     Serial.print("T: ");
  31.     Serial.print(periodo);
  32.     Serial.print(" us - ");
  33.  
  34.     Serial.print("Freq: ");
  35.     Serial.print(frequencia,2);
  36.     Serial.println(" Hz");
  37.  
  38.     lcd.setCursor(0,0);
  39.     lcd.print("T=");
  40.     lcd.print(periodo);
  41.     lcd.print("us");
  42.     lcd.setCursor(0,1);
  43.     lcd.print("f=");
  44.     lcd.print(frequencia,2);
  45.     lcd.print("Hz");
  46.     delay(t);
  47.   }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement