pub toetsen
repeat i from 0to 8
inputreg[i]:=0
p:=0
repeat
if ina [noparse][[/noparse] 0..7 ]
if ina [noparse][[/noparse] 0 ]
inputreg[noparse][[/noparse] 0 ]:=1
elseif ina [noparse][[/noparse] 1 ]
inputreg[noparse][[/noparse] 1 ]:=1
elseif ina [noparse][[/noparse] 2 ]
inputreg[noparse][[/noparse] 2 ]:=1
elseif ina [noparse][[/noparse] 3 ]
inputreg[noparse][[/noparse] 3 ]:=1
elseif ina [noparse][[/noparse] 4 ]
inputreg[noparse][[/noparse] 4 ]:=1
elseif ina [noparse][[/noparse] 5 ]
inputreg[noparse][[/noparse] 5 ]:=1
elseif ina [noparse][[/noparse] 6 ]
inputreg[noparse][[/noparse] 6 ]:=1
elseif ina [noparse][[/noparse] 7 ]
inputreg[noparse][[/noparse] 7 ]:=1
if inputreg[noparse][[/noparse] 0 ]==1
if ina[noparse][[/noparse] 0 ]==0
p:=2
if inputreg[noparse][[/noparse] 1 ]==1
if ina[noparse][[/noparse] 1 ]==0
p:=2
if inputreg[noparse][[/noparse] 2 ]==1
if ina[noparse][[/noparse] 2 ]==0
p:=2
if inputreg[noparse][[/noparse] 3 ]==1
if ina[noparse][[/noparse] 3 ]==0
p:=2
if inputreg[noparse][[/noparse] 4 ] ==1
if ina[noparse][[/noparse] 4 ]==0
p:=2
if inputreg[noparse][[/noparse] 5 ]==1
if ina[noparse][[/noparse] 5 ]==0
p:=2
if inputreg[noparse][[/noparse] 6 ] ==1
if ina[noparse][[/noparse] 6 ]==0
p:=2
if inputreg[noparse][[/noparse] 7 ]==1
if ina[noparse][[/noparse] 7 ]==0
p:=2
if p:=2
repeat f from 0 to 1000
vertraag := 60_000
dira[noparse][[/noparse] 17 ] ~~
!outa[noparse][[/noparse] 17 ]
waitcnt(vertraag + cnt )
p:=0
[/i]
i need to detect when a switch is pushed and that it stayed pushed .. and this is how i wanted to do it ..
but it woul'd be handfull if i had an array in a second cog ... is this possible?
( for 1 or an other reason he don't add a setrain number after the inputreg's .. but know that there are and that the are for 0 to 7
i edited this oafter my post [noparse];)[/noparse])
Why do you think is most of your code "italic"? There must be an "[noparse][[/noparse] i]" somewhere I presume..
Nevertheless...
First we must bring your code into a shape so it does no longer hurt to look at it
if ina [noparse][[/noparse] 0 ]
inputreg[noparse][[/noparse] 0 ]:=1
elseif ina [noparse][[/noparse] 1 ]
inputreg[noparse][[/noparse] 1 ]:=1
elseif ina [noparse][[/noparse] 2 ]
inputreg[noparse][[/noparse] 2 ]:=1
elseif ina [noparse][[/noparse] 3 ]
inputreg[noparse][[/noparse] 3 ]:=1
elseif ina [noparse][[/noparse] 4 ]
inputreg[noparse][[/noparse] 4 ]:=1
elseif ina [noparse][[/noparse] 5 ]
inputreg[noparse][[/noparse] 5 ]:=1
elseif ina [noparse][[/noparse] 6 ]
inputreg[noparse][[/noparse] 6 ]:=1
elseif ina [noparse][[/noparse] 7 ]
inputreg[noparse][[/noparse] 7 ]:=1
This is no good at all... What do you want to do?
I think:
"For each of the numbers 1 to 7 check the corresponding pin and set the array element with the same number to TRUE ".
If it is so, then just write this down:
REPEAT pinNumber FROM 1 TO 7
IF INA[noparse][[/noparse]pinNumber]
inputreg[noparse][[/noparse]pinNumber] := TRUE
Please change the second part in the same spirit!
Note that "TRUE" is not "1" but "-1"; so you can also stick with "1" if you want.
ok .. but can i use an array in an other cog ?
because the code of above i want to use in an other cog ...
and how do i need to write the code .. (see an couple of post above )
Your question wrt "an array in another COG" makes to sense! There are no "arrays in COGs" in SPIN. Just use your array - it does not matter from which COG.
ok because you said in an aerlyer post that it was impossible .. or i must understand it wrong [noparse]:s:[/noparse]s
srry
so if i want to put a array in a new cog do i do it like this?
(1) "array[noparse][[/noparse]9]" fetches the value of trhat element and transfers it to the routine FLITS; that is most likely not what you want...
(2) "[noparse][[/noparse]...]" is a nice try, but does not work in SPIN; "[noparse][[/noparse]...]" only works for bits in an I/O register
What now?
(3) You can simply use "array[noparse][[/noparse]x]" INSIDE your routine! You need not transfer it via a parameter. This is called "global access" and workes fine. It is frowned upon by pundits, but they also do it when no-one is looking....
(4) you can use a "pointer", but we shall wait for that until next month....
or do i just use it in code the "array"
because i need values of an other code into this cog's ... and the code domes from outputreg[noparse][[/noparse] 9 ]
ok .. so i did that ..
but now i have a other issue i can't fix ..
i want to use a variable k that i can use in 2 cog ( in cag k = variable o (rules of the extra cog use) )
so this is my code
pub twister
coginit ( 6, toetsen(k), @stack)
repeat
if k==2
quit
pub toetsen(o)
repeat i from 0to 8
input[i]:=0
p:=0
repeat
REPEAT pinNumber FROM 0 TO 7
IF INA[noparse][[/noparse]pinNumber]
input[noparse][[/noparse]pinNumber] := 1
if input[noparse][[/noparse]pinNumber]==1
if ina[noparse][[/noparse]pinNumber]==0
p:=2
if p==2
repeat f from 0 to 1000
vertraag := 60_000
dira[noparse][[/noparse]17] ~~
!outa[noparse][[/noparse]17]
waitcnt(vertraag + cnt )
o:=2
p:=0
[/i]
so i need that the value in o is the same as in k but is this isn't right .. how do i get o back to k?
(1) I already asked you to put a blank after each [noparse][[/noparse] especially when you see that your code appeares italic then you have a [noparse][[/noparse] i somewhere.. Doing this will reduce misunderstandings
(2) You can either use another global variable rathen than a parameter-
(3) Or you have to use a "reference" or a "pointer" to a variable.
As this is not too obvious I shall give you an example.
VAR LONG a
....
COGNEW (proc(@A),..)
......
PRI proc(refa) | vala
vala := LONG[noparse][[/noparse] refa]
.....
LONG[noparse][[/noparse] refa] := 2
The example you gave showed that you are modifying the local parameter "o", which is not want you want, I think.
So I recommended (2) to use global variables.
I do not understand why you don't do it (or why you say "It doesn't work"), but if you want to use output parameters for what reason ever, I gave you the full example (3) how to do it in my previous posting.
a global variable is a variable that is defined under the VAR block .. if 'im not wrong ...
and o is defined under that .. so it is already a global variable.. but it doen't work .. that is what i'm saying
how shoul'd i declaire a gloabl variable then in an other pub ?
because you say it isn't possible ... btw i think if this is out .... the job is done.. i need to see a couple of things true .. but i think al the big job is over ...
You do notdeclare global variables in PUBs, you declare them in VAR.
When I say "It is not possible" I mean:
(1) Your code shows: You use "o" as a parameter -- BTW I am sure I warned you to use such names which will most likely lead to confusion (o, O, I)
(2) You SAY you use "o" as a global variable.
So either you are lying (which I do not assume) or you have changed your code...
i'm really srry to work on your nerves like that ..
but the fault is completely mine .. and this is because my englisch .. well we say some sentences differend in dutch then in englisch .. if you under stand what i maen ..
what i ment in my last post was that how shoul'd i say that i work with a global variable in tha cog ...
because now i just said that it was
pub teotsen ( o) but this is for a parameter you say .. how shoul'd i do it for a variable? don't wright anything ?
grtz
( srry that you had to lose your nerves because of me srry)
It would really help if you would finally read Chapter 3 in the Manual....
"Global" variables are called global, because you can use them freely in all routines of your object.
"Local" variables (as parameters) can only be used within a specific routine.
Everything you define in CONS, VAR or DAT (except local labels in assembly programs) is "global".
ok tnx ... now i know what to do ..
but i've a strange situation going on here .. and i don't get it .. even my father doesn't get it ..( and that never happend before)
this is the situation ..
evertime there is a button pushed input must go to 1 ..
if the you "release"( can't find the right word ) the button there must be a sound ..
i can do this 1 .... thi sloop the if i do it the second time ... it doesn't do this anymore .. than it works again .. not ..well ... etc.
this is the code .. maybe you can find what the prblem is ...
pub twister
coginit( 6,toetsen,@stack)
pri toetsen
i:=0
repeat i from 0 to 8
input[noparse][[/noparse] i]:=0
p:=0
repeat
REPEAT pinNumber FROM 0 TO 7
IF INA[noparse][[/noparse] pinNumber]
input[noparse][[/noparse] pinNumber] := 1
if input[noparse][[/noparse] pinNumber]==1
if ina[noparse][[/noparse] pinNumber]==0
p:=2
if p==2
repeat f from 0 to 1000
vertraag := 20_000
dira[noparse][[/noparse] 17] :=1
outa[noparse][[/noparse] 17]:=1
waitcnt(vertraag + cnt )
outa[noparse][[/noparse] 17]:=0
waitcnt(vertraag + cnt )
p:=0
i hope i made clear what he problem is ... if not .. let me know i will try to excplain it better
Difficult to say, as your indention is not correct...
The REPAT after IF should be indented...
But as you do not reset the "input" array elements, there will be more and more ones accumulated, so the sound should be played all the time...
Another short remark: it is unusual to write
if input[noparse][[/noparse] pinNumber]==1
if ina[noparse][[/noparse] pinNumber]==0
one generally uses
IF input[noparse][[/noparse] pinNumber]==1 AND ina[noparse][[/noparse] pinNumber]==0
which is the same but more readable.
In fact one would write that lines totally differently, but that part seems to do what you want at least...
The question is:Where do you want to reset the "input" elements?
Note that most switches or push buttons "bounce", which means when you press them, there wilj be a short mixture of "ons" and "offs", until it stays "on" as long as you press.
repeat i from 0 to 8
input[noparse][[/noparse] i]:=0
i put everything back to zero .. and the bounce of the switches .. isn't that dendering ? but i get what you want to say ..
and what do you mean about the The REPAT after IF should be indented...?
grtz
note: the indetion is well correct but i wrote it wrong here .. i will give you the code again:
pub toetsen
i:=0
repeat i from 0 to 8
input[noparse][[/noparse] i]:=0
p:=0
repeat
REPEAT pinNumber FROM 0 TO 7
IF INA[noparse][[/noparse] pinNumber]
input[noparse][[/noparse] pinNumber] := 1
IF input[noparse][[/noparse] pinNumber]==1 AND ina[noparse][[/noparse] pinNumber]==0
p:=2
if p==2
k:=2
repeat f from 0 to 1000
vertraag := 20_000
dira[noparse][[/noparse] 17] :=1
outa[noparse][[/noparse] 17]:=1
waitcnt(vertraag + cnt )
outa[noparse][[/noparse] 17]:=0
Well, if you do not indent the REPEAT, the IF p==2 will have no effect I should say.
You reset input in the very beginning, but after that you have an endless REPEAT loop.
But everything depends on the correct indention....
Comments
i have a question ..
if i want to put a array in a new cog do i do it like this?
coginit(6,array[noparse][[/noparse]9],@stack)
or like this
coginit (6, array [noparse][[/noparse]0..9], @stack)
There are SPIN interpreters in each of your COGs, no space for anything else!
You could write an assembly program...
But I think this is nor what you want...
So: What do you want to do with that array? Why do you want it "in a COG" in the first place??
i need to detect when a switch is pushed and that it stayed pushed .. and this is how i wanted to do it ..
but it woul'd be handfull if i had an array in a second cog ... is this possible?
( for 1 or an other reason he don't add a setrain number after the inputreg's .. but know that there are and that the are for 0 to 7
i edited this oafter my post [noparse];)[/noparse])
Post Edited (elecnoob) : 9/10/2007 8:43:50 PM GMT
Nevertheless...
First we must bring your code into a shape so it does no longer hurt to look at it
This is no good at all... What do you want to do?
I think:
"For each of the numbers 1 to 7 check the corresponding pin and set the array element with the same number to TRUE ".
If it is so, then just write this down:
Please change the second part in the same spirit!
Note that "TRUE" is not "1" but "-1"; so you can also stick with "1" if you want.
because the code of above i want to use in an other cog ...
and how do i need to write the code .. (see an couple of post above )
srry
so if i want to put a array in a new cog do i do it like this?
coginit(6,array[noparse][[/noparse]9],@stack)
or like this
coginit (6, array [noparse][[/noparse]0..9], @stack)
THERE ARE NO ARRAYS IN COGS !
THERE ARE NO ARRAYS IN COGS !
THERE ARE NO ARRAYS IN COGS !
THERE ARE NO ARRAYS IN COGS !
Sigh...
do i need to do it like this flits as a pub
coginit(6,flits (array[noparse][[/noparse]9]),@stack)
or like this
coginit (6, flits (array [noparse][[/noparse]0..9]), @stack)
i want to use a array in a pub srry srry srry that i said it wrong
then i just need to take 9 variable for doing the job or what ?
(1) "array[noparse][[/noparse]9]" fetches the value of trhat element and transfers it to the routine FLITS; that is most likely not what you want...
(2) "[noparse][[/noparse]...]" is a nice try, but does not work in SPIN; "[noparse][[/noparse]...]" only works for bits in an I/O register
What now?
(3) You can simply use "array[noparse][[/noparse]x]" INSIDE your routine! You need not transfer it via a parameter. This is called "global access" and workes fine. It is frowned upon by pundits, but they also do it when no-one is looking....
(4) you can use a "pointer", but we shall wait for that until next month....
it woul'd look like this
coginit(6, flits ,@stack)
pub flits ( array [noparse][[/noparse] 9 ] )
or do i just use it in code the "array"
because i need values of an other code into this cog's ... and the code domes from outputreg[noparse][[/noparse] 9 ]
but now i have a other issue i can't fix ..
i want to use a variable k that i can use in 2 cog ( in cag k = variable o (rules of the extra cog use) )
so this is my code
so i need that the value in o is the same as in k but is this isn't right .. how do i get o back to k?
jasper
(2) You can either use another global variable rathen than a parameter-
(3) Or you have to use a "reference" or a "pointer" to a variable.
As this is not too obvious I shall give you an example.
i'm already using a global variable so and still it doesn't work ..
but can't i do an update on that vaiable or something ?
grtz
So I recommended (2) to use global variables.
I do not understand why you don't do it (or why you say "It doesn't work"), but if you want to use output parameters for what reason ever, I gave you the full example (3) how to do it in my previous posting.
and o is defined under that .. so it is already a global variable.. but it doen't work .. that is what i'm saying
This is not possible, when "o" is a global variable.
I am sure you changed a lot in your program in the meantime. So please post what does not work as you expect.
because you say it isn't possible ... btw i think if this is out .... the job is done.. i need to see a couple of things true .. but i think al the big job is over ...
When I say "It is not possible" I mean:
(1) Your code shows: You use "o" as a parameter -- BTW I am sure I warned you to use such names which will most likely lead to confusion (o, O, I)
(2) You SAY you use "o" as a global variable.
So either you are lying (which I do not assume) or you have changed your code...
I think it's best to stop this...
but the fault is completely mine .. and this is because my englisch .. well we say some sentences differend in dutch then in englisch .. if you under stand what i maen ..
what i ment in my last post was that how shoul'd i say that i work with a global variable in tha cog ...
because now i just said that it was
pub teotsen ( o) but this is for a parameter you say .. how shoul'd i do it for a variable? don't wright anything ?
grtz
( srry that you had to lose your nerves because of me srry)
"Global" variables are called global, because you can use them freely in all routines of your object.
"Local" variables (as parameters) can only be used within a specific routine.
Everything you define in CONS, VAR or DAT (except local labels in assembly programs) is "global".
but i've a strange situation going on here .. and i don't get it .. even my father doesn't get it ..( and that never happend before)
this is the situation ..
evertime there is a button pushed input must go to 1 ..
if the you "release"( can't find the right word ) the button there must be a sound ..
i can do this 1 .... thi sloop the if i do it the second time ... it doesn't do this anymore .. than it works again .. not ..well ... etc.
this is the code .. maybe you can find what the prblem is ...
i hope i made clear what he problem is ... if not .. let me know i will try to excplain it better
grtz
The REPAT after IF should be indented...
But as you do not reset the "input" array elements, there will be more and more ones accumulated, so the sound should be played all the time...
Another short remark: it is unusual to write
one generally uses
which is the same but more readable.
In fact one would write that lines totally differently, but that part seems to do what you want at least...
The question is:Where do you want to reset the "input" elements?
Note that most switches or push buttons "bounce", which means when you press them, there wilj be a short mixture of "ons" and "offs", until it stays "on" as long as you press.
i put everything back to zero .. and the bounce of the switches .. isn't that dendering ? but i get what you want to say ..
and what do you mean about the The REPAT after IF should be indented...?
grtz
note: the indetion is well correct but i wrote it wrong here .. i will give you the code again:
waitcnt(vertraag + cnt )
p:=0
Post Edited (elecnoob) : 9/16/2007 1:45:54 PM GMT
You reset input in the very beginning, but after that you have an endless REPEAT loop.
But everything depends on the correct indention....