do while(condition) condition not working

Hi,

you all know 30 seconds i hope... i have made the same but with a count down... i tried to use do while but i think there's something wrong with my condition because he doesn't want to get my words on the lcd. can anyone help me out?

i also want to make a button so if you have guessed the word, you can go to the next one, because now there is a delay on it, but it has to be a button.

here's my code

#include <LiquidCrystal.h>

char *dewoorden[]={"Nederland", "Nietmachine", "Jan Smit", "Vos", "De Koning", "Einstein", "Veerboot", "Besmettelijk", "Veerboot", "Directeur", "Miley Cyrus", "Sinterklaasjournaal", "Bloedzuiger", "Vampier", "Johan Cruijff", "Chucky", "Pizzabezorger", "Spiderman", "Waterpolo", "Diarree", "Dierenarts", "Sluitingstijd", "Ketting", "Meppen", "Insect", "Bassie en Adriaan", "Zalm", "Dick Advocaat", "Star Wars", "Justin Bieber", "Duitsland", "Gebarentaal", "Freddie Mercury", "Eddy Murphy", "Gebarentolk", "Luier", "Hoorn", "Wie is de Mol", "Heinz", "Jumbo", "Kerstman", "Ed Sheeran", "Friesland", "Hoesten", "Tunnel", "Nee", "Schaar", "Gember", "Tomaat", "Schitzel", "Appelsap", "Tandenborstel", "Tandpasta", "Slavinkje", "Orgaan", "Atlantis", "Titanic", "WC bril", "Postbode", "Laptop", "Pieter Post", "Minecraft", "Fortnite", "Steam", "Ganzenbord", "Plastic bak", "Frankrijk", "Basisschool", "Mummie", "Neus", "Boom", "Amazonegebied", "Astma", "Europa", "Piraten", "Jack Sparrow", "Klemtoon", "Voetbal", "Waterhoofd", "Brum", "Olifant", "Tom Holland", "Speaker", "Dora", "Teletubies", "Dick Trom"};
long woorden;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int Vs = 45;
int countdown = 1;
int S = 0;

void setup() {
 randomSeed(200);
 // set up the LCD's number of columns and rows:
 lcd.begin(16, 2);
 lcd.setCursor(15, 1);
 lcd.print("S");
 lcd.setCursor(13, 1);
 S = Vs;
}

void loop() {
 do {
   if (S>=10) {
     lcd.setCursor(13,1);
   }
   if (S<10) {
     lcd.setCursor(14, 1);
   }
   S = Vs - countdown;
   lcd.print(S);
   Vs = S;
   delay(1000);
   lcd.setCursor(0, 1);
   lcd.print("                                                                   ");
   lcd.setCursor(15, 1);
   lcd.print("S");
   if (S<1) {
     lcd.clear();
     lcd.setCursor(3, 0);
     lcd.print("Game  Over");
     delay(5000);
     lcd.clear();
     lcd.setCursor(2, 0);
     lcd.print("Next  Player");
     delay(5000);
     lcd.clear();
     lcd.setCursor(3, 0);
     lcd.print("Click Next");
     lcd.setCursor(1, 1);
     lcd.print("Player  button");
     delay(5000);
   }
 }
 
 while(S>=1); {
   woorden = random(sizeof(dewoorden)/sizeof(char*));
   lcd.clear();
   lcd.setCursor(0, 0);
   lcd.print(dewoorden[woorden]);
 }
}

oh yeah... im 14 and dutch so plz don't use difficult words

Please edit your post to add code tags, as described in How to use this forum.

Then, clearly describe the problem.

Before adding a button input, study and make sure you understand the Button examples that come with the Arduino software.

is this better?

Thanks for posting the code correctly.

This won't work for at least two reasons:

 while(S>=1); {
   woorden = random(sizeof(dewoorden)/sizeof(char*));
  1. the ";" after the while makes the while statement an infinite, do-nothing loop, if S>=1.

  2. After you fix (1), S must change in the while loop, or it will still be an infinite loop.

but i want it to loop until S is 0

Then you must make S change in the while loop.

Simple example:

int S=10;
while (S > 1) {
Serial.println(S);
S--;
}

The while() belongs to the previous do{}.

@Tvh_05, What lcd.print() statement is not executed?

lcd.print(dewoorden[woorden]);

dewoorden means 'the words'

he doesn't want to show it on the lcd screen while the countdown is counting down... and i dont understand how i put the code of jremington in my code... im a little bit of a copy paste dude because its a project for school

im a little bit of a copy paste dude because its a project for school

That is not the way to learn to program. But, when you put it that way, it sounds like you aren't interested in learning.

The while() belongs to the previous do{}.

Thanks, I missed that. The start of the gratuitous code block is confusing.

Does the LCD work at all?
If not, dump it for now, and check your logic using Serial.

yes he is working... everything in do is working, even if i switch do and while code... but while is the problem

oh yeah... i forgot to say that... i was left behind by my group who i work with, and im the only programmer... and i have to finish this before tomorrow. if i had more time, i would gladly learn al this but i dont have time.

Tvh_05:
yes he is working... everything in do is working, even if i switch do and while code... but while is the problem

The forum has a Dutch section, if English is a problem.

check your logic using Serial.

{
   woorden = random(sizeof(dewoorden)/sizeof(char*));
   lcd.clear();
   lcd.setCursor(0, 0);
   lcd.print(dewoorden[woorden]);
 }

It looks correct. There is an extra set of brackets, but that is not the issue.

long woorden;
char *dewoorden[]={"Nederland", "Nietmachine", "Jan Smit", "Vos", "De Koning", 
"Einstein", "Veerboot", "Besmettelijk", "Veerboot", "Directeur", 
"Miley Cyrus", "Sinterklaasjournaal", "Bloedzuiger", "Vampier", "Johan Cruijff", 
"Chucky", "Pizzabezorger", "Spiderman", "Waterpolo", "Diarree", 
"Dierenarts", "Sluitingstijd", "Ketting", "Meppen", "Insect", 
"Bassie en Adriaan", "Zalm", "Dick Advocaat", "Star Wars", "Justin Bieber", 
"Duitsland", "Gebarentaal", "Freddie Mercury", "Eddy Murphy","Gebarentolk", 
"Luier", "Hoorn", "Wie is de Mol", "Heinz", "Jumbo", 
"Kerstman", "Ed Sheeran", "Friesland", "Hoesten", "Tunnel", 
"Nee", "Schaar", "Gember", "Tomaat", "Schitzel", 
"Appelsap", "Tandenborstel", "Tandpasta", "Slavinkje", "Orgaan", 
"Atlantis", "Titanic", "WC bril", "Postbode", "Laptop", 
"Pieter Post", "Minecraft", "Fortnite", "Steam", "Ganzenbord",
"Plastic bak", "Frankrijk", "Basisschool", "Mummie", "Neus", 
"Boom", "Amazonegebied", "Astma", "Europa", "Piraten", 
"Jack Sparrow", "Klemtoon", "Voetbal", "Waterhoofd", "Brum", 
"Olifant", "Tom Holland", "Speaker", "Dora", "Teletubies",
"Dick Trom"};

void setup() {
 Serial.begin(115200);
 Serial.println(sizeof(dewoorden));
 Serial.println(sizeof(char*));
 Serial.println((sizeof(dewoorden)/sizeof(char*)));
}

void loop() {
   woorden = random(sizeof(dewoorden)/sizeof(char*));
   //lcd.clear();
   //lcd.setCursor(0, 0);
   Serial.print(woorden);
   Serial.print('\t');
   Serial.println(dewoorden[woorden]);
   delay(1000);
}

Tvh_05:
lcd.print(dewoorden[woorden]);

dewoorden means 'the words'

he doesn't want to show it on the lcd screen while the countdown is counting down... and i dont understand how i put the code of jremington in my code... im a little bit of a copy paste dude because its a project for school

It did print "dewoorden[woorden]". But the loop() starts again and it prints "S" by "lcd.print(S);"

Try adding a delay().

can't i print both at the same time when one is in a do() and the other in a while() ?