Go Down

Topic: 使用timer.setinterval出現無法轉換的問題 (Read 199 times) previous topic - next topic

Mikelouis

想要使用blynk接收訊息,但是在使用timer.setInterval(1000L, Show_Acc);會出現以下error:invalid conversion from 'void (*)(int)' to 'timer_callback {aka void (*)()}' [-fpermissive],請幫我看一下哪裡出了問題,謝謝。

Quote
void setup(){
     Wire.begin();
     Serial.begin(115200);  // start serial for output. Make sure you set your Serial Monitor to the same!

     delay(500);
     Serial.println("\nSetup, init");
     Blynk.begin(auth, ssid, pass);
   
     timer.setInterval(1000L, Show_Acc);
     I2C_Bus_Check();

     YAL210_Initial(YAL210_I2C_Addr);

     Serial.println("\n***************************Start loop***************************");
     }
     
//==============================Arduino loop function==============================//
void loop(){
     
     Show_Acc(YAL210_I2C_Addr);
     Serial.println();
     delay(100);
     Blynk.run();
     timer.run();
     }
Quote
void Show_Acc(int YAL210_I2C_Addr){
     float X_CNT=0,  Y_CNT=0,  Z_CNT=0, X_G=0, Y_G=0, Z_G=0;
 
     YAL210_acc_t rawAccel = YAL210_acc.readRawAccel(YAL210_I2C_Addr);

#ifdef calibration
     // Display the results (acceleration is measured in m/s^2)
     X_CNT = rawAccel.XAxis - AccOffset.XAxis;
     Y_CNT = rawAccel.YAxis - AccOffset.YAxis;
     Z_CNT = rawAccel.ZAxis - AccOffset.ZAxis;
#else
     X_CNT = rawAccel.XAxis;
     Y_CNT = rawAccel.YAxis;
     Z_CNT = rawAccel.ZAxis;
#endif     
     
     X_G   = ((X_CNT / (pow(2,Resolution) / (Range * 2))) * 9.81);
     Y_G   = ((Y_CNT / (pow(2,Resolution) / (Range * 2))) * 9.81);
     Z_G   = ((Z_CNT / (pow(2,Resolution) / (Range * 2))) * 9.81);
     Blynk.virtualWrite(V1, X_CNT);
     Blynk.virtualWrite(V2, Y_CNT);
     Blynk.virtualWrite(V3, Z_CNT);
     Blynk.virtualWrite(V4, X_G);
     Blynk.virtualWrite(V5, Y_G);
     Blynk.virtualWrite(V6, Z_G);
     delay(10);
     Serial.print("X Axis: "); Serial.print(X_CNT);Serial.print(" counts ( ");
     Serial.print(X_G); Serial.print(" m/s^2 )"); Serial.print("\t\t");

     Serial.print("Y Axis: "); Serial.print(Y_CNT);Serial.print(" counts ( ");
     Serial.print(Y_G); Serial.print(" m/s^2 )"); Serial.print("\t\t");

     Serial.print("Z Axis: "); Serial.print(Z_CNT);Serial.print(" counts ( ");
     Serial.print(Z_G); Serial.print(" m/s^2 )"); Serial.print("\t\t");
     }

Go Up