For beginners : frequent mistake...

BESQUEUT

Senior Member
Code:
Alarm:

    for I= 0 to 9
       high doorbell
       pause 100
       low doorbell
    next I

return
Seem to sound doorbell every 200 ms...
but a pause is missing !

This one works as expected and is shorter...
Code:
Alarm:                  ' supposing Doorbell is low at start
    for I= 0 to 9
       toggle doorbell
       pause 100
    next I
return
 

Bill.b

Senior Member
Without the second pause the output returns to high with microseconds.
Code:
Alarm:

    for I= 0 to 9
       high doorbell
       pause 100
       low doorbell
       pause 100
    next I

return
The problem with the second example is the output can be high at the end of the sub, therefore you have to set an initial state of the output
or ensure the number of loops will result in the output being low.


Bill
 
Last edited:

BESQUEUT

Senior Member
The problem with the second example is the output can be high at the end of the sub, therefore you have to set an initial state of the output
or ensure the number of loops will result in the output being low.
Yes : we have to put doorbell low at the start of the program.
If (this is probably a bug) the doorbell is continuously high, I think that the user will debug his code...
or put a low at start of the sub.
With 10 loops or any even number, the doorbell will be at the same state when return. So, if low, it will be low.
 
Top