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.
I could also make freq a variable to change the blink rate correct?
Certainly. Both counters (A & can be used for a total of 16 LEDs provided they are not used otherwise (video/audio etc). You can also mis/use the Synth object (PropTool library) if you prefer.
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.
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.
pub PULSELED ( pin -- ) \ pulse and led smoothly
DUP \ dup the pin number on the stack
A \ select CTRA
APIN \ assign pin to apin of counter A, still have one pin # on the stack
#1000 HZ \ start CTRA in NCO mode at 1000 Hz
B \ select CTRB
APIN \ just grabbed the last pin # off the stack, assinged to CTRB
#1001 HZ \ start CTRB in NCO mode at 1001 Hz
;
pub MUTEALL A MUTE B MUTE ; \ turn both counters off
/ usage #14 PULSELED or whatever your pin number is
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.
What does the waitpne(0,0,0) do? What do the 0's mean?
If I don't place it there then the method exits and the cog stops. The waitpne is there to keep the cog alive (zero can never be not equal to 0 & ina). For your usage scenarios just ignore it.
As for steady on I'd simply set outa[pin] high (and reset it for the blink mode), e.g.
Certainly. Both counters (A & can be used for a total of 16 LEDs provided they are not used otherwise (video/audio etc). You can also mis/use the Synth object (PropTool library) if you prefer.
So now I'm thinking of a way to shut it off if I have either had it blinking or on solid. Here is what I came up with. Is there an easier way to do this?
This doesn't work: ctrx(led3, 0{0:A|1:B}, 5{0:off|1..6}, N{0:flash|N:solid})
Ah, I see. This (being an inline comment for PropTool's Summary display mode) just means any number but 0 (just the way I do things). So you can pass anything from e.g. 1..4000 (N sort of stands for Number). Sorry for the confusion.
So I was looking at this code again today and was wondering if there was a way to count the "flashes"? What I am lookiing at doing was to use this method as a way to indicate a condition for troubleshooting. For example we've all seen the instructions that if the red led blinks so many times, then pauses it means one thing etc.
I like the way that this code piece works in that it doesn't use a cog and works independant of other processes.
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.
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.
CON
_clkmode = xtal1 + pll16x 'Standard clock mode * crystal frequency = 80 MHz
_xinfreq = 5_000_000
' grnK -----;------->|-----------;----/\/\-- redK
' '-------|<-----------' Ω
redK = 16
grnK = 17
PUB Main
'' 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.
autoFlash(20, 80, 50)
PUB autoFlash(frqR, frqG, phsG)
dira[redK..grnK]~~
ctra := 100_000 << 23 + redK ' NCO mode
ctrb := 100_000 << 23 + grnK ' NCO mode
phsb := (posx / 100 * phsG) << 1 '
frqa := frqR '
frqb := frqG
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:
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: