I working on a project that would use a lcd to display different words. To do this I also use timer1 for an ISR to determine when to stop displaying words.
When reading how to create an ISR with timers one of the drawbacks listed of using timer1 was that pin11 had shared functionality on the arduino and both functions could not be used at the same time.
http://letsmakerobots.com/node/28278 under the pitfalls section
I am unsure what that means and if my code currently violates that. If someone could clarify this for me that would be great.
I believe i have attached my entire code on this project so if there is anything at looks wrong let me know as this is my first coding project on the arduino.
Thanks in advance.
edit as reading through my code I found an error where under a certain situation I leave the ISR by just typing
loop;
to take me back to the main loop section I feel like this would not reset the interrupts and I think it might cause an issue with the stack. I'll try and fix that myself but I would love input on how to fix that.
catchphraseCode.ino (4.21 KB)
Thanks for the advice, I made changes that I think should resolve all of the issues. Mainly, I removed the timers for interrupts and looked up what millis() does to use as my timer. I included the changes to void loop here. the only other changes was simplifying the setup and removing the ISR.My only question is why would my print statements have not worked? was it because they could be interrupted by the ISR while attempting to print? If so then it should no longer a problem or is it something I still need to address?
thanks again for the advice!
void loop(){
lcd.setCursor(0,2); // initialize to top corner
lcd.print("press button");
lcd.setCursor(0,3);
lcd.print("to start"); //let people know how to start
do{ //wait for button to be pressed
val = digitalRead(inPin);
}while(val==LOW);
startTime=millis(); //button has been clicked/ get start time
endTime= startTime+180000; //three minutes after the start time
endGame=LOW;
do{
check=0; // set my checker value to zero (i want a new word each time button is pressed)
myWord= getWord(); // get new word method
lcd.clear(); //clear display
lcd.setCursor(0, 1); // (note: line 1 is the second row, since counting begins with 0):
lcd.print(myWord); //print new word
do
{ //keep the word displayed until button pressed or time ran out
val=digitalRead(inPin); //check for button to be pressed
if(val==HIGH){ // button was pressed
check=1; // set check variable high
}
curTime=millis();
if (curTime>endTime){ //out of time
check=1; //leave inner loop
endGame=HIGH; //leave outer loop
lcd.clear();
lcd.setCursor(0,0);
lcd.print("previous game ended");
}
}while(check==0); // go back to while(1) loop to get another word
}while(endGame==LOW);
}