starting and stopping blinking LED's 'blinker2.spin'
Rob v.d. berg
Posts: 86
Hi,
I'm playing with the Blinker2.spin code. With LED[noparse][[/noparse]NextObject].Start(16, 3_000_000, 0)·the LED is blinking· forever.·It's·working great.
What·is the·best way to add code for stopping and·later starting the blinking LED's on·demand, or·input (switch). In the·"(Ch3-Ex07)-Output" object there is a STOP function,·i don't·understand·how to use. Is this for stopping all the LED's?
Any idea's??
Rob.
{{ Blinker2.spin }}
CON
· _CLKMODE = XTAL1 + PLL16X···· 'Set to ext low-speed crystal, 4x PLL
· _XINFREQ = 5_000_000········ 'Frequency on XIN pin is 5 MHz
· MAXLEDS· = 4················ 'Number of LED objects to use
· Button_1 = 20· ' for·switching LED nr 1, PIN 16
···
OBJ
· LED[noparse][[/noparse]MAXLEDS] : "(Ch3-Ex07)-Output"
· BS2·· : "BS2_Functions"······ 'create BS2 Object·
PUB Main
· BS2.start (31,30)
{Toggle pins at different rates, simultaneously}
· dira[noparse][[/noparse]16..19]~~······························ 'Set pins to outputs
·
· LED[noparse][[/noparse]NextObject].Start(16, 3_000_000, 0)····· 'Blink LEDs
· LED[noparse][[/noparse]NextObject].Start(17, 6_000_000, 0)
· LED[noparse][[/noparse]NextObject].Start(18, 9_000_000, 0)
· LED[noparse][[/noparse]NextObject].Start(19, 12_000_000, 0)
·
· repeat········································ 'Loop endlessly
····if ina[noparse][[/noparse]Button_1] == 0 ' I have add the blue code·
····· LED[noparse][[/noparse]x].Stop······ ·'x·=·1 to 4 is not working
·····
PUB NextObject : Index
{Scan LED objects and return index of next available LED object.
·Scanning continues until one is available.}
· repeat
··· repeat Index from 0 to MAXLEDS-1
····· if not LED[noparse][[/noparse]Index].Active
······· quit
· while Index == MAXLEDS
I'm playing with the Blinker2.spin code. With LED[noparse][[/noparse]NextObject].Start(16, 3_000_000, 0)·the LED is blinking· forever.·It's·working great.
What·is the·best way to add code for stopping and·later starting the blinking LED's on·demand, or·input (switch). In the·"(Ch3-Ex07)-Output" object there is a STOP function,·i don't·understand·how to use. Is this for stopping all the LED's?
Any idea's??
Rob.
{{ Blinker2.spin }}
CON
· _CLKMODE = XTAL1 + PLL16X···· 'Set to ext low-speed crystal, 4x PLL
· _XINFREQ = 5_000_000········ 'Frequency on XIN pin is 5 MHz
· MAXLEDS· = 4················ 'Number of LED objects to use
· Button_1 = 20· ' for·switching LED nr 1, PIN 16
···
OBJ
· LED[noparse][[/noparse]MAXLEDS] : "(Ch3-Ex07)-Output"
· BS2·· : "BS2_Functions"······ 'create BS2 Object·
PUB Main
· BS2.start (31,30)
{Toggle pins at different rates, simultaneously}
· dira[noparse][[/noparse]16..19]~~······························ 'Set pins to outputs
·
· LED[noparse][[/noparse]NextObject].Start(16, 3_000_000, 0)····· 'Blink LEDs
· LED[noparse][[/noparse]NextObject].Start(17, 6_000_000, 0)
· LED[noparse][[/noparse]NextObject].Start(18, 9_000_000, 0)
· LED[noparse][[/noparse]NextObject].Start(19, 12_000_000, 0)
·
· repeat········································ 'Loop endlessly
····if ina[noparse][[/noparse]Button_1] == 0 ' I have add the blue code·
····· LED[noparse][[/noparse]x].Stop······ ·'x·=·1 to 4 is not working
·····
PUB NextObject : Index
{Scan LED objects and return index of next available LED object.
·Scanning continues until one is available.}
· repeat
··· repeat Index from 0 to MAXLEDS-1
····· if not LED[noparse][[/noparse]Index].Active
······· quit
· while Index == MAXLEDS
Comments
in the code posted above a variable named "x" is not defined
you have to define in the VAR-section of your SPIN-File
to me it's not really clear what you mean with "on demand"
please make a celar and detailed description what you would like to do
With the posting above I can't decide which is the best way to do it
Anyway to make a suggestion of ONE way is the following
The method NextObject gives back the number of the next free LED-object
What is easier to understand is if you make the LED-Object-No hardcoded
ATTENTION !
arrays are defined with the number of elements her MAXLED = 4
BUT ! the first element has NOT number 1 it has number 0 !
so the index runs from 0 to 3 which is 0 to MAXLED - 1
best regards
Stefan
thanks,·yes i know about the array. I want to stop and start·a LED by a switch like the code below. This·is working well.·Is this the smallest code ?, maybe the test <if not LED[noparse][[/noparse]0].Active> can be implemented in the object?
· repeat········································ 'Loop endlessly
··· if ina[noparse][[/noparse]Button_1] == 0·
····· LED[noparse][[/noparse]0].Stop
··· else··········
····· if not LED[noparse][[/noparse]0].Active
······· LED[noparse][[/noparse]0].Start(16, 25_000_000, 0)
Regards,
Rob
I'm again not sure what you mean exactly
implemented in WHICH object ?
Do you mean implementing the test <if not LED[noparse][[/noparse]0].Active> in the "(Ch3-Ex07)-Output"-object ?
best regards
Stefan
Yes, so you·don't·need to do that in·your main program.
Rob.
you can do that
but how does the object know WHEN to do it
other than the MAIN-program tells the object to do so
If it is just inside the "(Ch3-Ex07)-Output"-object it is there but it has to be called
from outside the object
best regards
Stefan
Your are right, it's clear for me how it's works.
Thanks,
Rob
·