Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Frequenzimetro by Xfox
- #include <LiquidCrystal.h>
- const int in = A0;
- const int out = 3;
- LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
- long tempo1 = 0;
- long tempo2 = 0;
- double T = 0;
- double f = 0;
- long wait = 0;
- void setup() {
- Serial.begin(19200);
- lcd.begin(16, 2);
- pinMode(in, INPUT);
- pinMode(out, OUTPUT);
- Serial.println("Start");
- splashscreen();
- mostra();
- }
- void loop(){
- if (digitalRead(in) == LOW){
- tempo1 = millis();
- for (digitalRead(in); digitalRead(in) != HIGH; ){
- }
- tempo2 = millis();
- }
- T = tempo2 - tempo1;
- T = T * 0.001;
- f = 1 / T;
- mostra();
- seriale();
- }
- void mostra(){
- if (wait < millis()){
- wait = millis() + 50;
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("f: ");
- if (f > 1000){
- f = f / 1000;
- lcd.print(f);
- lcd.print(" KHz");
- }
- else{
- lcd.print(f);
- lcd.print(" Hz");
- }
- lcd.setCursor(0,1);
- if (T < 0.001){
- T = T * 1000;
- lcd.print("T: ");
- lcd.print(T);
- lcd.print(" ms");
- }
- else{
- lcd.print("T: ");
- lcd.print(T);
- lcd.print(" s");
- }
- }
- }
- long wait_seriale = 0;
- void seriale(){
- if (wait_seriale < millis()){
- wait_seriale = millis() + 1000;
- Serial.print("T = ");
- Serial.print(T);
- Serial.print("\t");
- Serial.print("T2 = ");
- Serial.print(tempo2);
- Serial.print("\t");
- Serial.print("T1 = ");
- Serial.print(tempo1);
- Serial.print("\t");
- Serial.print("f = ");
- Serial.print(f);
- Serial.print("\t");
- Serial.println();
- }
- }
- void splashscreen(){
- lcd.clear();
- lcd.print("Xfox & Arduino");
- lcd.setCursor(0, 1);
- lcd.print("Frequency");
- delay(2000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement