Hi all,
I am working on the Crystal Ball project#11 and would really appreciate it if someone could help me troubleshoot the following issue. Thank you in advance.
LCD displays 'Ask the Crystal ball'
When I ask the question and tilt the switch a response is also displayed.
But the LCD doesn't display the first message again 'Ask the Crystal ball' for the next question. I am not sure how to refresh it. I turned potentiometer and also tilt switch but that doesn't help. I basically plugged off and on again for the next question. Is that what we are supposed to do each time?
Well, if you are talking about the potentiometer on the display, there is no point mucking about with it once you have the display set to the correct contrast.
But since most of us have no idea what set of projects you are talking about, you need to at least read the instructions and post your code as well as giving the web link to the project#11 in question.
if (switchState != prevSwitchState) {
if (switchState == LOW) {
reply = random(8);
lcd.clear(); // clears the writing
lcd.setCursor(0, 0);
lcd.print("The ball says:");
lcd.setCursor(0, 1);
switch(reply){ // the program will enter the case
case 0:
lcd.print("Yes");
break;
case 1:
lcd.print("Most likely");
break;
case 2:
lcd.print("Certainly");
break;
case 3:
lcd.print("Outlook good");
break;
case 4:
lcd.print("Unsure");
break;
case 5:
lcd.print("Ask again");
break;
case 6:
lcd.print("Doubtful");
break;
case 7:
lcd.print("No");
break;
}
}
}
piasb:
But the LCD doesn't display the first message again 'Ask the Crystal ball' for the next question.
...
I basically plugged off and on again for the next question. Is that what we are supposed to do each time?
That is simply how the code is (simply!) written. Note that the lines to display the prompt are in "setup()". This means they are only ever executed when the Arduino comes out of reset.
The code in "loop()" repeats - and does so extremely fast unless something contained takes time. The lcd.print calls do take a small fraction of a second but overall it is checking the switch very quickly and responding if necessary. I presume that what actually happens is that as you actuate the (tilt) switch, the message will actually change in a "random" manner, possibly appearing quite erratic. If it does that, it is merely following the code.
I will leave it to you to determine when and where in the code you wish to insert the instructions (copy from setup()) to re-issue the challenge. Because it will over-write the "answer" you will need to think carefully as to how to do that.
And frankly, it is thoroughly crappy code, but OTOH, you need to plan and think out carefully exactly what you want to happen, when and why and in what order, in order to write decent code.