Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. volatile int NbTopsFan1;
  2. volatile int NbTopsFan2;
  3. #include <LiquidCrystal.h>
  4. int Calc1;
  5. int Calc2;
  6. int hallsensor1 = 2; //Arduino Pin von Sensor 1
  7. int hallsensor2 = 3; //Arduino Pin von Sensor 2
  8. LiquidCrystal lcd(9, 8, 6, 5, 4, 10);
  9. void rpmSensor1 () //Interrupt funktion für Sensor 1
  10. {
  11. NbTopsFan1++; //Impulszählvariable Sensor 1 +1
  12. }
  13.  
  14. void rpmSensor2 () //Interrupt funktion für Sensor 2
  15. {
  16. NbTopsFan2++; //Impulszählvariable Sensor 2 +1
  17. }
  18.  
  19. void setup()
  20. {
  21. Serial.begin(9600);
  22. pinMode(hallsensor1, INPUT); //Initialisiert Pin als Input
  23. pinMode(hallsensor2, INPUT); //Initialisiert Pin als Input
  24. attachInterrupt(digitalPinToInterrupt(hallsensor1), rpmSensor1, RISING);
  25. attachInterrupt(digitalPinToInterrupt(hallsensor2), rpmSensor2, RISING);
  26. lcd.begin(16, 2);
  27. //delay(500);
  28. }
  29.  
  30. void loop ()
  31. {
  32. NbTopsFan1 = 0;
  33. NbTopsFan2 = 0;
  34. sei(); //interrupts aktivieren (also darauf hören und funktion ausführen und nicht ignorieren)
  35. delay (1000); //Wait 1 second
  36. cli(); //interrupts deaktivieren (also nicht darauf hören und somit ignorieren)
  37. Calc1 = (NbTopsFan1 * 60 / 300); //(Pulse frequency x 60) / 5Q, = flow rate in L/min
  38. Calc2 = (NbTopsFan2 * 60 / 300);
  39.  
  40. lcd.setCursor(1, 0);
  41. lcd.print("In: ");
  42. lcd.print (Calc1, DEC); //Ausgabe des errechneten Durchflusses von Sensor 1
  43. lcd.print (" L/min.");
  44.  
  45. lcd.setCursor(1, 1);
  46. lcd.print("Out:");
  47. lcd.print (Calc2, DEC); //Ausgabe des errechneten Durchflusses von Sensor 2
  48. lcd.print (" L/min.");
  49.  
  50.  
  51. Serial.print (Calc2, DEC); //Prints the number calculated above
  52. Serial.print (" L/min. OUT\r\n"); //Prints "L/hour" and returns a new line
  53. Serial.print (Calc1, DEC); //Prints the number calculated above
  54. Serial.print (" L/min. IN \r\n"); //Prints "L/hour" and returns a new line
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement