Function 在Arduino中如何在类内使用布尔函数?

Function 在Arduino中如何在类内使用布尔函数?,function,class,arduino,boolean,Function,Class,Arduino,Boolean,我正在为MPR121传感器制作一个库,我想在Arduino IDE的类中使用bool函数,但它不起作用。 这是我的密码 #include <Wire.h> #include "Adafruit_MPR121.h" #ifndef _BV #define _BV(bit) (1 << (bit)) #endif Adafruit_MPR121 cap = Adafruit_MPR121(); uint16_t lasttouched = 0; uint16_t currt

我正在为MPR121传感器制作一个库,我想在Arduino IDE的类中使用bool函数,但它不起作用。 这是我的密码

#include <Wire.h>
#include "Adafruit_MPR121.h"
#ifndef _BV
#define _BV(bit) (1 << (bit)) 
#endif
Adafruit_MPR121 cap = Adafruit_MPR121();
uint16_t lasttouched = 0;
uint16_t currtouched = 0;

class PaperTron {
  private:          
         uint8_t i;
         uint8_t a;
  public:
  PaperTron(){
}

void touchBegin(){
    Serial.begin(9600);
  Serial.println("Hi! I'm PaperTron.");
  if (!cap.begin(0x5A)) {
  Serial.println("Error! TOUCH pins not found. Please check wiring.");
  while (1);
  }
  Serial.println("Hurray! Now you can use my TOUCH pins.");
}  

**//This is the boolean function which is not working**
bool isHigh(uint8_t touchpin) {
  currtouched = cap.touched();
  for (i=0; i<12; i++) {
    if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
      if(i==touchpin) return true;  
    }
      if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) {
      if(i==touchpin) return false;
      }
  }
  lasttouched = currtouched;
 }
};

PaperTron papertron;
void setup() {
    papertron.Begin();
    papertron.touchBegin();
}

void loop() {
if(papertron.isHigh(2)){Serial.println("Hello");}
}
#包括
#包括“Adafruit_MPR121.h”
#如果没有

#定义(位)(1)如果循环检查所有位,但未发现任何更改,那么高的
应该返回什么?您如何将其与已更改的位区分开来?对于未返回值的函数,我会预期编译错误-除非我读错了所有值。@aMike函数返回高的值,这就是if条件变为高的原因执行。