不知道我为什么会这样做。
该程序是一个严重编码的捣蛋鼹鼠游戏在Arduino Uno上运行。
我的IED是Arduino IED版本1.6.12
是的,如果您想查看所有代码,请选择将其删除,但还有更多内容。
错误
Arduino: 1.6.12 (Windows 7), Board: "Arduino/Genuino Uno"
C:\Users\Strings\Documents\Arduino\Too_Many_Moles\Too_Many_Moles.ino: In function 'void winOrLost()':
Too_Many_Moles:146: error: invalid use of void expression
timelyCall(current_millis, toggleBuzer(), 1000);
^
C:\Users\Strings\Documents\Arduino\Too_Many_Moles\Too_Many_Moles.ino: In function 'void loop()':
Too_Many_Moles:191: error: invalid use of void expression
timelyCall(current_millis, popAMole(), time_interval);
^
exit status 1
invalid use of void expression
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Main.ino
const int buzer = A0, on_off_pin = A1;
unsigned long current_millis;
const int time_interval = 20;
int currentMole = 0;
int points = 0, lives = 3, level = 0, odds_of_pop_up = 6;
mole moles[6] = {
mole( 2, 8 ),
mole( 3, 9 ),
mole( 4, 10 ),
mole( 5, 11 ),
mole( 6, 12 ),
mole( 7, 13 )
};
int number_of_mole = sizeof(moles) / sizeof(*moles);
void timelyCall(unsigned long currentMillis, void (&f)(), int ms) {
if (millis() - currentMillis > ms) {
f();
currentMillis = millis();
}
}
void popAMole() {
if (moles[currentMole].isReadyToPop()) {
moles[currentMole].popUp(odds_of_pop_up);
}
if (currentMole + 1 <= number_of_mole) {
currentMole = 0;
}
else {
currentMole++;
}
}
mole.h
#ifndef mole_h
#define mole_h
#include "Arduino.h"
class mole
{
public:
mole(int p_out, int p_in);
void resetMole();
void popUp(int odds);
boolean moleGetHit();
boolean isReadyToPop();
void setUpTimer(int up_timer);
int getUpTimer();
void decrementUpTimer();
void setRecoveryTimer(int recovery_timer);
int getRecoveryTimer();
void decrementRecoveryTimer();
void addRecoveryTimer(int add_time);
boolean getSouldBeUp();
int getOddsOfPopinh();
void setOddsOfPopinh(int odds);
int getPinIn();
private:
boolean _sould_be_up = false;
int _up_timer = 0;
int _recovery_timer = 0;
int _pin_out;
int _pin_in;
int _odds_of_poping = 10;
};
#endif
mole.cpp
boolean mole::isReadyToPop() {
if (_recovery_timer == 0 && _sould_be_up = false) {
return true;
}
else {
return false;
}
}
void mole::popUp(int odds) {
if (rand() % odds + 1 == 1) {
digitalWrite(_pin_out, HIGH)
_sould_be_up = true;
}
}
答案 0 :(得分:2)
您正在调用未将地址传递给timelyCall
的函数!
timelyCall(current_millis, popAMole(), time_interval);
timelyCall(current_millis, toggleBuzer(), 1000);
应该是:
timelyCall(current_millis, popAMole, time_interval);
timelyCall(current_millis, toggleBuzer, 1000);
请注意popAMole
&amp;上没有括号toggleBuzer
。