Blinking led with counter
Don M
Posts: 1,652
I remember that sometime ago there was a discussion about being able to blink an led by only using the counter. I can't find the thread or sample code someone posted.
Comments
So I can use this within any cog then?
I could also make freq a variable to change the blink rate correct?
This may be the thread you remember where a bi-colored LED was driven with a pair of Prop pins.
Flashing a Bi-Colored LED in 7 ways
My version, written in FemtoBasic, allows the Bi-Colored LED can be controlled with steady state and blinking modes in 3 colors as well as OFF.
The technique can easily be translated into other languages.
Duane J
Make-an-LED-pulse-smoothly-go-on-and-off-without-any-code-interaction
Now I can't help myself, Peter I will get you!
In Tachyon
Need some help understanding what is happening with your example:
What does the waitpne(0,0,0) do? What do the 0's mean?
I added this code to my object and it will make the LED blink but it just stops here. If I comment out the waitpne statement then it still blinks but continues on in the code.
How should this code be used? I want it to blink a x speed for 1 mode then be steady on for another mode. If I change the frqa to 0 then it goes off.
Thanks.
As for steady on I'd simply set outa[pin] high (and reset it for the blink mode), e.g. Clearing phsa makes sure that the ouput isn't driven (even with frqa == 0).
So if I just use it without the waitpne I can use it in an existing cog and just vary the parameters to my liking?
Sorry for the dumb questions just trying to understand it.
Thanks.
What do you think? Try it and see!
On another note however using a Quickstart board I can't get this to work-
I get an error message on compile- "Expected a constant, unary operator, or "(" "
But this will work-
Why won't it work?
Using a variable pin should read constant(%0_00100_000 << 23) | pin.
That is because the local variable pin can't be resolved as a constant at compile time. But 16 can.
ctra := constant(%0_00100_000 << 23 | pin)
Ok. Thanks for that.
Here's some code I put your methods to use with. Works pretty neat-
Note, your mode 2 wouldn't touch the counter so if it's still running it will continue doing so. Did you mean to clear dira[pin] in that mode?
Alternative version using "A" and "B":
Regarding this: mode{0:flash|N:solid} should N be a 1 instead of N ?
Here's what works: ctrx(led3, 0{0:A|1:B}, 5{0:off|1..6}, 1{0:flash|1:solid})
This doesn't work: ctrx(led3, 0{0:A|1:B}, 5{0:off|1..6}, N{0:flash|N:solid})
That said, "N" would work ...
I like the way that this code piece works in that it doesn't use a cog and works independant of other processes.
Any idea if this could be done and how to do it?
Edit: Periodic pulse trains would be OK though, e.g. 10 pulses followed by fixed state (on or off) for the same time then pulses again.
For example, if you have a bi-color 2-pin led between two pins,
The above PUB with different choices of the parameters generates various alternating patterns of red and green that are easily identifiable (at least for anyone not blind to those colors--always have to consider that possibility when making indicators!)
examples:
20,10,0 red, green, pause, repeat
10,20,0 green, red, pause, repeat
20, 60,0 red,pause,green,pause, repeat
20,80,0 red,red,green,green,pause,repeat
80,20,0 green,green,red,red,pause,repeat
10,110,00 5 green,5 red, repeat
10,130,00 6 green,6 red, repeat
Play with both small integer ratios and as also larger numbers to achieve smooth effects.The third parameter, the starting phase (in percent from 0 to 99%), adds a measure of syncopation.
Tracy- I tried your method on a Quickstart and couldn't make it work. Now I know that I am not using bi-color led's back to back but thought I'd at least see one of the led's blink.
If I can use this method only using 1 led and get the patterns you describe with the 1 led then I can use this.
Here's my code. Maybe it's something I'm doing wrong.
I tried various numbers for the phase- 0, 50, 99 and none of them blinked.
Now I noticed in an earlier thread above the code was done like this: