' demo of sleep() for one second minus time to execute code inside a do loop ' also has an LED blinker - red, green, both, ... ' stevech@san.rr.com Private blinkLED1Stack(1 To 30) as byte const RTCticksPerSecond as integer = cint(1.0/0.00195) sub main() dim h as byte, m as byte dim n as long dim sec as single dim s as string calltask blinkLED1, blinkled1stack do n = register.rtctick call gettime(h, m, sec) ' get VM's time since reset ' make string like 00:00:00.0 time s=byteToAscii2(h) & ":" & byteToAscii2(m) & ":" & _ byteToAscii2(cbyte(sec)) & "." & byteToAscii2(cbyte(100.0 * fraction(sec))) console.writeline(s) sleep(RTCticksPerSecond - cint(Register.RTCTick+1-n)) ' sleep for balance of this second (approx) loop end sub ''''''''''''''''''''''''''' ' return a two digit ASCII version of n (assume 0 <= n <= 99 private function byteToAscii2(byval n as byte) as STRING byteToAscii2 = iif(n < 10, "0" & cstr(n), cstr(n)) byteToAscii2 = mid(byteToAscii2, 1, 2) end function Sub blinkLED1() dim b as byte register.ddrd = register.ddrd or &HA0 ' two LEDs are output bits register.portd = &HA0 b=&H20 Do call watchdog() 'debug.print "blinkLED1" Call ToggleBits(Register.PortD, b) sleep(4) Call ToggleBits(Register.PortD, b) sleep(512-8) select case b ' choose next LED value case &H20 b = &H80 case &H80 b = &HA0 case &HA0 b = &H20 end select Loop End Sub