#There is a delay() function?

24 messages · Page 1 of 1 (latest)

keen glacier
#

In arduino you can use delay() to wait for a certain number of milliseconds before moving on to the next line of code. In Java is it possible?

plain pulsarBOT
#

This post has been reserved for your question.

Hey @keen glacier! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

slender compass
#

You can use ‘Thread.sleep(milliseconds)’ to freeze the main thread. That will wait

keen glacier
slender compass
#

Have you got to exception catching yet?

keen glacier
#

how i can do?§

slender compass
#

one moment

frail crescent
#

try checking that out ^

keen glacier
slender compass
#

In Java, you can deal with an exception in two ways, you can catch it, or you can throw it. Catching it would entail surronding the exception generating code in a try-catch block, which will trigger code in the catch section once an exception in throw. It'd look something like this try { Thread.sleep(1000); } catch (InterruptedException e) { //If the code fail and an exception is thrown, the code in this block will run e.printStackTrace(); }

keen glacier
#

ok so i can write like:

#

case 2: System.out.println("Macchina in spegnimento..."); try { Thread.sleep(1000); } catch (InterruptedException e) { //If the code fail and an exception is thrown, the code in this block will run e.printStackTrace(); } System.out.println("Macchina spenta!"); System.exit(0); //se è spenta il programma finisce break;

#

?

#

@slender compass

slender compass
#

Yes

keen glacier
#

Thank you!

plain pulsarBOT
# keen glacier Thank you!

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.

keen glacier
#

i run the code and it start

#

i hope you will have a good day! 🙂

slender compass
#

thank you

#

Make sure to close the post if your done with it

keen glacier
#

ok