Advertisement
Guest User

Untitled

a guest
Dec 21st, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <LiquidCrystal.h>
  2.  
  3. LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
  4. #define pulse_ip A1
  5. int ontime, offtime, duty;
  6. float freq, period;
  7.  
  8. void setup()
  9. {
  10.   pinMode(pulse_ip, INPUT);
  11.   lcd.begin(16, 2);
  12.   lcd.clear();
  13. }
  14. void loop()
  15. {
  16.   lcd.setCursor(0, 0);
  17.   lcd.print("Freq:");
  18.   lcd.setCursor(0, 1);
  19.   lcd.print("Duty:");
  20.   ontime = pulseIn(pulse_ip, HIGH);
  21.   offtime = pulseIn(pulse_ip, LOW);
  22.   period = ontime + offtime;
  23.   freq = 1000000.0 / period;
  24.   duty = (ontime / period) * 100;
  25.   lcd.setCursor(6, 0);
  26.   lcd.print(freq);
  27.   lcd.print("Hz");
  28.   lcd.setCursor(6, 1);
  29.   lcd.print(duty);
  30.   lcd.print('%');
  31.   delay(1000);
  32.   lcd.clear();
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement