Please help with SLEEP

tarantulataramasalata

Senior Member
Hi, I am trying to use the SLEEP command with an 08M2 and was wondering if my program is using the command properly?

Thanks :)

main:
if pinC.3 = 1 then
high C.1
pause 1000
low C.1
pause 500
low C.1
pause 1000
high C.1
pause 500
high C.1
pause 1000
low C.1
pause 500
low C.1
pause 1000
high C.1
call sleeping
else
call sleeping
endif
stop

sleeping:
sleep 65535
return
 

hippy

Ex-Staff (retired)
wondering if my program is using the command properly?
Probably not, in the sense it may not be doing what you expect it to.

SLEEP sleeps for units of 2.3 seconds or there about, so you are sleeping for 150000 seconds, 2500 minutes or 42 hours.

That's possibly longer than you were intending.

http://www.picaxe.com/BASIC-Commands/Time-Delays/sleep

Also, the program doesn't have a loop in it so it ends anyway, either after pulsing the outputs or immediately ( after sleeping ).
 
Last edited:

BESQUEUT

Senior Member
This code is equivalent to your's, with Hippy remarks
Code:
[color=Black]main:[/color]
[color=Blue]do
  if [/color][color=Purple]pinC.3 [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]then
      high C.1
      pause [/color][color=Navy]1000
      [/color][color=Blue]low C.1
      pause [/color][color=Navy]500
      [/color][color=Blue]low C.1     [/color][color=Green]' this does not do anything as C.1 is already low
      [/color][color=Blue]pause [/color][color=Navy]1000
      
      [/color][color=Blue]high C.1
      pause [/color][color=Navy]500
      [/color][color=Blue]high C.1    [/color][color=Green]' this does not do anything as C.1 is already high
      [/color][color=Blue]pause [/color][color=Navy]1000
      
      [/color][color=Blue]low C.1
      pause [/color][color=Navy]500
      [/color][color=Blue]low C.1     [/color][color=Green]' this does not do anything as C.1 is already low
      [/color][color=Blue]pause [/color][color=Navy]1000
      [/color][color=Blue]high C.1
  endif

  sleep [/color][color=Navy]10  [/color][color=Green]' 23 s for tests purposes 65535[/color]
[color=Blue]loop[/color]
Note that if pinC.3 = 1 or not, you call "sleeping".
So it's not necessary to use a subprogram.
See others comments in code.
 
Last edited:
Top