technoblogy / ulisp

A version of the Lisp programming language for ATmega-based Arduino boards.
http://www.ulisp.com/
MIT License
372 stars 45 forks source link

Can't escape from delay #58

Closed technoblogy closed 12 months ago

technoblogy commented 1 year ago

If you evaluate a delay, such as:

(delay 10000)

you can't escape with '~'.

dragoncoder047 commented 12 months ago

The easiest solution I can think of is to replace the single delay() call with a while loop

unsigned long ms = /* time to delay */;
while (--ms) {
  delay(1);
  testescape();
}
technoblogy commented 12 months ago

Good suggestion. More accurate is:

object *fn_delay (object *args, object *env) {
  (void) env;
  object *arg1 = first(args);
  unsigned long start = millis();
  unsigned long total = checkinteger(arg1);
  do testescape();
  while (millis() - start < total);
  return arg1;
}
dragoncoder047 commented 12 months ago

Ah, I forgot that testescape() takes a small, but significant, amount of time to run.