Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.21 KB | None | 0 0
  1. volatile int FlowPulse; //measuring the rising edges of the signal
  2. volatile int FlowPulse1; //measuring the rising edges of the signal
  3. int Calc;
  4. int Calc1;
  5. int Calc2;
  6. int flowsensor = 2; //The pin location of the sensor
  7. int flowsensor1 = 3; //The pin location of the sensor
  8.  
  9. void setup() {
  10.  
  11. pinMode(flowsensor, INPUT); //initializes digital pin 2 as an input
  12. Serial.begin(9600); //This is the setup function where the serial port is initialised,
  13. attachInterrupt(0, rpm, RISING); //and the interrupt is attached
  14.  
  15. pinMode(flowsensor1, INPUT); //initializes digital pin 2 as an input
  16. Serial.begin(9600); //This is the setup function where the serial port is initialised,
  17. attachInterrupt(1, rpm1, RISING); //and the interrupt is attached
  18.  
  19.  
  20. }
  21.  
  22. void loop() {
  23.  
  24. FlowPulse = 0; //Set NbTops to 0 ready for calculations
  25. sei(); //Enables interrupts
  26. delay(1000); //Wait 1 second
  27. cli(); //Disable interrupts
  28. Calc = (FlowPulse * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate in L/hour
  29. Serial.print (Calc, DEC); //Prints the number calculated above
  30. Serial.print (" L/hour\r\n"); //Prints "L/hour" and returns a new line
  31.  
  32. FlowPulse1 = 0; //Set NbTops to 0 ready for calculations
  33. sei(); //Enables interrupts
  34. delay(1000); //Wait 1 second
  35. cli(); //Disable interrupts
  36. Calc1 = (FlowPulse1 * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate in L/hour
  37. Serial.print (Calc1, DEC); //Prints the number calculated above
  38. Serial.print (" L/hour1\r\n"); //Prints "L/hour" and returns a new line
  39.  
  40. sei(); //Enables interrupts
  41. delay(2000); //Wait 1 second
  42. cli(); //Disable interrupts
  43. Calc2 = (Calc - Calc1);
  44. Serial.print (Calc2, DEC); //Prints the number calculated above
  45. Serial.print (" L/hour rozdil\r\n"); //Prints "L/hour" and returns a new line
  46. Serial.print ("  \r\n");
  47.  
  48. sei(); //Enables interrupts
  49. delay(1000); //Wait 1 second
  50. cli(); //Disable interrupts
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. }
  58.  
  59. void rpm () //This is the function that the interupt calls
  60. {
  61. FlowPulse++; //This function measures the rising and falling edge of the hall effect sensors signal
  62.  
  63. }
  64.  
  65. void rpm1 () //This is the function that the interupt calls
  66. {
  67. FlowPulse1++; //This function measures the rising and falling edge of the hall effect sensors signal
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement