I have a bs2. I have a program that blinks a led on and off. I need the led to blink 10 times and then end the program. Any ideas on how to do this? Do I use a count command? If so how do I do that?
The COUNT statement is used to count external pulses. It stops your program for the amount of time specified in the COUNT statement, counts how many pulses occur on an I/O pin you specify during that time, and leaves the count in the variable you specify, then your program continues.
For your particular needs, look at the FOR / NEXT statement chapters in the Stamp Basic Syntax and Reference Manual. You can download this from Parallax if you don't have it already. There are also examples in the "What's a Microcontroller?" tutorial also downloadable from Parallax.
Go to the main Parallax webpage and click on the Resources tab, then click on Downloads, then Stamps in Class Downloads.
If you just want the LED to blink on and off, just use a for next loop
counter VAR Byte ' counter variable to hold what count number you are on
led PIN 15 ' one leg of LED connected to this pin with proper resistance in series
FOR counter = 1 TO 10 ' counter starts off as 1
HIGH led ' whatever pin you wish to change state
PAUSE 500 ' half second pause
LOW led ' same pin you wish to change state
PAUSE 500 ' half second pause
NEXT ' adds one to counter and returns to FOR again if counter < 10
' when counter = 10 then the loop breaks and goes to next piece of code or just put END to stop the program
To change how any times it blinks just change the 10 to whatever number of blinks you want. To change duration, change the pause duration. Hope this helps.
Thanks that was great help. But I want to control 4 relays for a certain time and at the end a tone
will sound.I have the program and the program for tone working but I cannot get it to step to the next relay
any ideas? I want to use the same sound for each relay. How do i get it to second relay after sound.
(next,return)?
You want to make "sound" into a subroutine. Then you can call it with GOSUB each place you need it. Read the chapter on the GOSUB and RETURN statements in the Stamp Manual.
GOSUB relay1 'contains Relay ON, Time, Relay OFF code, ends with RETURN
GOSUB sound 'contains code for tone including nested sub, end with RETURN
PAUSE xxx 'optional pause before relay2
GOSUB relay2
GOSUB sound
PAUSE
GOSUB relay3 .....
a more efficient way would be to have one generic Relay subroutine to which you would pass parameters indicating which output you wish to control and how much time.
I guess you could also use a for next loop for higher time
counter VAR Byte 'holds the counter
FOR counter = 1 TO 15 'cycles 15 times
PAUSE 60000 '60,000 milliseconds = 60 seconds = 1 minute
NEXT 'when counter = 15, loop breaks
'total duration of time will be 900,000 milliseconds which is 15 minutes
The pause function is limited but I think this for... next loop can just cycle what the pause function is capable of and achieve your desired pause. Hope this helps!
Comments
The COUNT command is used to count INCOMING pulses.
I would use a FOR...NEXT loop
FOR temp = 1 TO 10
' Your blink code
NEXT
Of course you will have to declare the variable "temp".
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There is a fine line between arrogance and confidence. Make sure you don't cross it...
·
For your particular needs, look at the FOR / NEXT statement chapters in the Stamp Basic Syntax and Reference Manual. You can download this from Parallax if you don't have it already. There are also examples in the "What's a Microcontroller?" tutorial also downloadable from Parallax.
Go to the main Parallax webpage and click on the Resources tab, then click on Downloads, then Stamps in Class Downloads.
To change how any times it blinks just change the 10 to whatever number of blinks you want. To change duration, change the pause duration. Hope this helps.
will sound.I have the program and the program for tone working but I cannot get it to step to the next relay
any ideas? I want to use the same sound for each relay. How do i get it to second relay after sound.
(next,return)?
relay 1
sound
relay 2
sound
relay 3
sound
relay 4
GOSUB relay1 'contains Relay ON, Time, Relay OFF code, ends with RETURN
GOSUB sound 'contains code for tone including nested sub, end with RETURN
PAUSE xxx 'optional pause before relay2
GOSUB relay2
GOSUB sound
PAUSE
GOSUB relay3 .....
a more efficient way would be to have one generic Relay subroutine to which you would pass parameters indicating which output you wish to control and how much time.
after 255 so it never reaches 900ms.
The pause function is limited but I think this for... next loop can just cycle what the pause function is capable of and achieve your desired pause. Hope this helps!