attachInterrupt 在库代码中不起作用

问题描述 投票:0回答:0

我想从流量传感器读取数据。我使用的是yf s201流量传感器。我在网络中找到一个使用的代码。代码正在运行,但我想要一个 make libray。所以我制作了一个 cpp 和 h 文件。但是代码“attachInterrupt”给出了一个错误。我无法修复它。错误是:

错误:从“void ()(flow_t)”到“void (*)()”的无效转换 [-fpermissive] attachInterrupt(digitalPinToInterrupt(5), pulseCounter, FALLING);

我添加了我的 cpp h 和主鳕鱼

void flow_measurement(flow_t* sensor, int price) {
  if (millis() - sensor->previousMillis >= sensor->interval) {
    sensor->flowRate = sensor->pulseCount / sensor->calibrationFactor;
    sensor->flowMilliLitres = (sensor->flowRate / 60) * 1000;
    sensor->totalMilliLitres += sensor->flowMilliLitres;
    sensor->totalLitre = sensor->totalMilliLitres / 1000.0;
    sensor->totalFiyat = sensor->totalLitre * price;
    sensor->previousMillis = millis();
    sensor->pulseCount = 0;
  }
}

void IRAM_ATTR pulseCounter(flow_t *sensor) 
{
  sensor->pulseCount ++;
}


header code 
typedef struct {
  int flow_pin;
  long currentMillis;
  long previousMillis;
  int interval;
  float calibrationFactor;
  volatile int pulseCount;
  float flowRate;
  unsigned int flowMilliLitres;
  unsigned long totalMilliLitres;
  float totalLitre;
  float totalFiyat;

} flow_t;


void flow_sensor_Init(flow_t *sensor, int pin_value);
void pulseCounter(flow_t *sensor);
void flow_measurement(flow_t *sensor, int price);

and main code

these two are in setup
flow_sensor_Init(&water_flow, 5);
  attachInterrupt(digitalPinToInterrupt(5), pulseCounter, FALLING);

I apologize for my english. thank you for helping

`

arduino interrupt flow
© www.soinside.com 2019 - 2024. All rights reserved.