flat assembler
Message board for the users of flat assembler.

flat assembler > Heap > Better let MCU beginner use sleep or setTimeout?

Author
Thread Post new topic Reply to topic
l4m2



Joined: 15 Jan 2015
Posts: 648
Code:
void flash() {
  while (1) {
    LEDPORT = !LEDPORT;
    sleep (500);
  }
}    
Code:
void flash() {
  LEDPORT = !LEDPORT;
  setTimeout (flash, 500);
}    
Post 31 Jan 2019, 02:12
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16664
Location: In your JS exploiting you and your system
The first will block forever.

The second will return after toggling the port.

So it depends upon your goal as to which best fits your need.
Post 31 Jan 2019, 04:17
View user's profile Send private message Visit poster's website Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 669
Post 31 Jan 2019, 07:48
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4201
Location: 2018
better directlly use a function of "time"
Code:
void flash() {
 static int t=0;
 t++;
 if (t == 500) {
  t = 0;
  LEDPORT = !LEDPORT;
 }
}
    
Post 02 Feb 2019, 10:07
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.