6v6gt:
This code will never be executed if the call to wpEncounter() is made when analogRead(0) is less than (or equal to) 100. This is because the code above is in a while loop, where the loop condition is while (analogRead(0) > 100) .
Therefore, the sketch will loop continuously because wpProceed, wpCS, and wpRetry are all false.
I suggest you add the following lines to the top of wpEncounter() and you will (almost certainly) see that the infinte loop (hang) occurs when wpEncounter() is called when the value of analogRead(0) is less than 100.
Serial.print("Entering wpEncounter(). photocell A0 = ");
Serial.println( analogRead(0) ) ;
Ohhhhhhhhh. I understand now.
I just tested this, however, and that doesn't seem to be the cause:
wpCheckScreen debug check:
Looped. wpCS:0; wpRetry:1; wpProceed:0
Next encounter!
wpRetry/Loop debug check:
Looped. wpCS:0; wpRetry:0; wpProceed:1
Entering wpEncounter(). photocell A0 = 246 ***<-----***
wpProceed debug check:
wpCS:0; wpRetry:0; wpProceed:0
wpRetry/Loop debug check:
Looped. wpCS:0; wpRetry:0; wpProceed:0
wpRetry/Loop debug check:
Looped. wpCS:0; wpRetry:0; wpProceed:0
wpRetry/Loop debug check:
Looped. wpCS:0; wpRetry:0; wpProceed:0
Attached is the most recent code, with the suggestions from @aarg and with time3 and time4 renamed to 'wpTimeout' and 'wpTimeoutCheck' to be more descriptive.
wild-only-debug-newest.ino (11.7 KB)
6v6gt
February 29, 2016, 8:22am
22
It does look then like it is leaving wpEncounter() without setting wpCS = true.
You have two blocks in wpEncounter() which break out of the loop before printing any debug information. For example:
{
wpProceed = false;
wpCS = true;
wpTimeout = 0;
wpTimeoutCheck = 0;
break; // <<<<<<<<<<<<<<<<<<<<<<<
Serial.println("wpEncounter debug check:" );
Serial.print("Looped. wpCS:" );
Serial.print(wpCS) ;
Serial.print("; wpRetry:" );
Serial.print(wpRetry) ;
Serial.print("; wpProceed:" );
Serial.println(wpProceed) ;
}
You should move the break statements after the debug statements like this example :
{
wpProceed = false;
wpCS = true;
wpTimeout = 0;
wpTimeoutCheck = 0;
Serial.println("wpEncounter debug check:" );
Serial.print("Looped. wpCS:" );
Serial.print(wpCS) ;
Serial.print("; wpRetry:" );
Serial.print(wpRetry) ;
Serial.print("; wpProceed:" );
Serial.println(wpProceed) ;
break; // <<<<<<<<<<<<<<<<<<<<<<<
}
Then run the program again to see if you get any more information.
Finally back, school was kicking my ass.
Anyway, I moved the break function to the end. This is what it gave me:
Entering wpEncounter(). photocell A0 = 238
wpProceed debug check:
wpCS:0; wpRetry:0; wpProceed:0
wpRetry/Loop debug check:
Looped. wpCS:0; wpRetry:0; wpProceed:0
wpRetry/Loop debug check:
Looped. wpCS:0; wpRetry:0; wpProceed:0
wpRetry/Loop debug check:
Looped. wpCS:0; wpRetry:0; wpProceed:0
. . .
. . .
Is there even anything else to try?
6v6gt
March 13, 2016, 11:45am
24
AegisCave:
. . .
Anyway, I moved the break function to the end. This is what it gave me:
. . .
There were two places where a break statement could have forced an exit from the loop in wpEncounter() before writing the debug statements.
Did you change them both ?
Very odd is that wpEncounter() exits without writing a single debug statement.
May be it is a good time to post your latest code.
The only change I made (that I can recall) was moving both 'break;' functions to the end.
Like so:
void wpEncounter()
{
Serial.print("Entering wpEncounter(). photocell A0 = ");
Serial.println( analogRead(0) ) ;
delay(1000);
unsigned long wpTimeout;
unsigned long wpTimeoutCheck;
wpTimeout = millis();
while (analogRead(0) > 100)
{
holdDown();
delay(500);
releaseDown();
wpTimeoutCheck = millis();
if (analogRead(0) < 100)
{
wpProceed = false;
wpCS = true;
wpTimeout = 0;
wpTimeoutCheck = 0;
Serial.println("wpEncounter debug check:" );
Serial.print("Looped. wpCS:" );
Serial.print(wpCS) ;
Serial.print("; wpRetry:" );
Serial.print(wpRetry) ;
Serial.print("; wpProceed:" );
Serial.println(wpProceed) ;
break;
}
if ((wpTimeoutCheck - wpTimeout) > 300000)
{
battleCount++;
Serial.print("Longest screen blackout: ");
Serial.print(longestTime);
Serial.println(" ms.");
Serial.print("Wild Encounters: ");
Serial.println(battleCount);
Serial.println("DESYNCH- Debug and restart");
Serial.println("Reason: Failed to find pokemon in 5 minutes. (Are you in the right area?)");
Serial.println("rip shinybot x.x");
Serial.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
battleCount = 0;
longestTime = 0;
wpTimeout = 0;
wpTimeoutCheck = 0;
wpCS = false;
wpRetry = false;
wpProceed = false;
sadbuzzer();
break;
}
delay(100);
holdUp();
delay(550);
releaseUp();
if (analogRead(0) < 100)
{
wpProceed = false;
wpCS = true;
wpTimeout = 0;
wpTimeoutCheck = 0;
// for debugging
Serial.println("");
Serial.println("wpEncounter debug check:" );
Serial.print("Looped. wpCS:" );
Serial.print(wpCS) ;
Serial.print("; wpRetry:" );
Serial.print(wpRetry) ;
Serial.print("; wpProceed:" );
Serial.println(wpProceed) ;
break;
}
delay(100);
}
}
That said, full code is attached below.
wild-only-debug-edited.ino (11.9 KB)
6v6gt
March 27, 2016, 10:42pm
26
It is leaving wpEncounter() without doing anything. There is gap in the logic if analogRead(0) returns exactly 100. Anyway I've added a pair debug statements at the end wpEncounter() which you could try:
void wpEncounter()
{
Serial.print("Entering wpEncounter(). photocell A0 = ");
Serial.println( analogRead(0) ) ;
delay(1000);
unsigned long wpTimeout;
unsigned long wpTimeoutCheck;
wpTimeout = millis();
while (analogRead(0) > 100)
{
holdDown();
delay(500);
releaseDown();
wpTimeoutCheck = millis();
if (analogRead(0) < 100)
{
wpProceed = false;
wpCS = true;
wpTimeout = 0;
wpTimeoutCheck = 0;
Serial.println("wpEncounter debug check:" );
Serial.print("Looped. wpCS:" );
Serial.print(wpCS) ;
Serial.print("; wpRetry:" );
Serial.print(wpRetry) ;
Serial.print("; wpProceed:" );
Serial.println(wpProceed) ;
break;
}
if ((wpTimeoutCheck - wpTimeout) > 300000)
{
battleCount++;
Serial.print("Longest screen blackout: ");
Serial.print(longestTime);
Serial.println(" ms.");
Serial.print("Wild Encounters: ");
Serial.println(battleCount);
Serial.println("DESYNCH- Debug and restart");
Serial.println("Reason: Failed to find pokemon in 5 minutes. (Are you in the right area?)");
Serial.println("rip shinybot x.x");
Serial.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
battleCount = 0;
longestTime = 0;
wpTimeout = 0;
wpTimeoutCheck = 0;
wpCS = false;
wpRetry = false;
wpProceed = false;
sadbuzzer();
break;
}
delay(100);
holdUp();
delay(550);
releaseUp();
if (analogRead(0) < 100)
{
wpProceed = false;
wpCS = true;
wpTimeout = 0;
wpTimeoutCheck = 0;
// for debugging
Serial.println("");
Serial.println("wpEncounter debug check:" );
Serial.print("Looped. wpCS:" );
Serial.print(wpCS) ;
Serial.print("; wpRetry:" );
Serial.print(wpRetry) ;
Serial.print("; wpProceed:" );
Serial.println(wpProceed) ;
break;
}
delay(100);
}
Serial.print("Leaving wpEncounter(). photocell A0 = "); //new
Serial.println( analogRead(0) ) ; //new
}