1
이 gameProcess 함수에서 if ladder와 for 루프에 문제가 있습니다. 근본적으로 (모드 == 1) 루프의 for 루프는 전혀 입력되지 않으며 이유는 확실하지 않습니다.Arduino for loop for
나는 (모드 == 1)을 (모드 == 0)으로 전환하면 (모드 == 1) for 루프가 입력 될 것이기 때문에 위치 지정과 관련이 있다고 생각하지만 (모드 == 0)하지 않습니다. 이것에 잠시 머물러있어 기능이 무엇인지 알아낼 수 없습니다. 어떤 도움이라도 대단히 감사하겠습니다. 감사.
// 5 means 10 switches as one iteration is a change between one mode to another, not on and off.
int gameProcess(int mode) {
Serial.println("> Starting game process.");
// 4 second delay between
int interval = 1000;
int initialDelay = 5000;
enter code here:
//delay(initialDelay);
if (mode == 1) {
// for a standard 25 round with a 2 sec interval
Serial.println("starting mode 1");
for (int i; i < 51; i++) {
Serial.println("In loop");
Serial.println(interval);
flickPin(13);
workingDelay(interval);
}
Serial.println("finished mode 1");
} else if (mode == 2) {
while(true) {
flickPin(13);
int minRandVal = 1000;
int maxRandVal = 15000;
int randomDelay = random(minRandVal, maxRandVal);
Serial.println(randomDelay);
workingDelay(randomDelay);
}
} else if (mode == 0) {
// for 10 rounds. Find out why it needs 35 and not 20.
Serial.println(" - Mode 0 .");
for (int i; i < 35; i++) {
Serial.println(interval);
flickPin(13);
workingDelay(interval);
}
Serial.println(" - finished Mode 0 .");
} else {
char error[80];
sprintf(error, "Unknown mode = %d", mode);
Serial.println(error);
}
}
여기서 gameProcess 함수가 호출되는 기본 루프와 initializeGame 함수가 있습니다.
int initializeGame(bool started, int mode) {
if (started == true) {
Serial.println(" -> in startMonitor, start button pressed");
Serial.println(mode);
gameProcess(mode);
// if the mode is 0 (none of the lights are on), that means it's in random mode and any interval between 5 and 60 secs come up until you stop it!
// set it back to false and turn the game light off because the game is over.
started = false;
digitalWrite(9, LOW);
} else {
started = false;
}
return started;
}
void loop()
{
// check if the pushbutton is pressed.
mode = stateMonitor(activeButton);
// now set the game mode led.
lightUpModeLed(ledPins[mode]);
// now check to see if the game has been initialized.
started = startMonitor(startButton, ledPins[4], started);
// read the state of the pushbutton value:
// initialize game if it hasn't already started.
// TODO this is where the loop will likely spend the majority of it's time so how can this be
started = initializeGame(started, mode);
saveData();
}
이 함수를 호출하는 방법을 보여줄 수 있습니까? 예를 들어 setup() 또는 loop()와 관련이 있습니까? 또한 첫 번째 if 문 바로 앞에있는 모드를 인쇄하지 않는 것이 좋습니다 (일시적으로 디버깅에 도움이 됨). –
Chris에게 주 루프를 포함하도록 질문을 편집했습니다. 이제 모드를 반향하고 그 결과를 살펴 보겠습니다. – jmood
하지만 예상대로 작동하지 않는 gameProcess() 코드는 어디에서 호출합니까? –