B4R Question attachInterrupt

Discussion in 'B4R Questions' started by AndroidMadhu, Aug 26, 2019.

  1. AndroidMadhu

    AndroidMadhu Member Licensed User

    Hello
    I m working on water flow sensor project and here to work with the water rotor system I need to use
    attachInterrupt().
    Could anyone suggest how I can make working water flow sensor without attachInterrupt()????
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Moved to the questions forum.
     
  3. AndroidMadhu

    AndroidMadhu Member Licensed User

    In Water flow sensor the attachInterrupt() function is required to get the pulse for the flow.
    Do I need to include attachInterrupt() in inline C/C++?
    Please suggest
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    You can see an example of using interrupts in rWire library.
     
  5. AndroidMadhu

    AndroidMadhu Member Licensed User

    Hi @Erel ,
    Could you please provide any link for the same? If possible... It will be helpful for me.
     
  6. Cableguy

    Cableguy Expert Licensed User

    Use the forum search engine, there many rWire related examples.
    Note that rWire is part is the standard B4R libs
     
  7. Erel

    Erel Administrator Staff Member Licensed User

  8. AndroidMadhu

    AndroidMadhu Member Licensed User

    Hello @Erel
    Thanks for the Link. The only problem is I cannot understand as how to incorporate the code using rWire library.
    Here is the code written in arduino. I am fine with all the calculation regarding water sensor. [YF-S201].
    But the only point I am not able to incorporate the attachInteruppt() using rWire.
    Below is the code from Arduino

    Code:
    void flow () // Interrupt function
    {
       flow_frequency++;
    }
    void setup()
    {
       pinMode(flowsensor, INPUT);
       digitalWrite(flowsensor, HIGH); // Optional Internal Pull-Up
       Serial.begin(9600);
       attachInterrupt(0, flow, RISING); // Setup Interrupt  <-------------- Here I am facing Issue
       sei(); // Enable interrupts   <--------- Here I am facing issue
       currentTime = millis();
       cloopTime = currentTime;
    }
    Could you please advice on this please.
     
  9. rbghongade

    rbghongade Active Member Licensed User

  10. Erel

    Erel Administrator Staff Member Licensed User

    You should use Pin.AddListener instead of an interrupt.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice