Conditional statement question.
JMLStamp2p
Posts: 259
Hello all,
If I wanted to check multiple Pins on my Prop what is the most efficient way to Code ? PUB Check_Pins method is Highlighted below.
Any advise would be appreciated.
...............................................................................................
CON
·_CLKMODE = XTAL1 + PLL1X····· 'External crystal 5MHZ times "1"
·_CLKFREQ = 5_000_000·········· ·'5 Million cycles
OBJ
·DELAY: "Clock"
·DATA: "FullDuplexSerial"
VAR
·long Stack [noparse][[/noparse]9]
·byte Byte_Recieved
·long Input_2
·long Input_3
PUB MAIN
·dira[noparse][[/noparse]0]~~
·dira[noparse][[/noparse]1]~
·dira[noparse][[/noparse]2]~
·dira[noparse][[/noparse]3]~
·data.start(1,0,0,9600)
·Run_Program
PUB Run_Program
·cognew((Check_Pins), @Stack)
...............................
PUB Check_Pins
·Input_2 := INA[noparse][[/noparse]2]
· If Input_2 == 0
·· Increment_Display
· ELSE·······················
·· Check_Pins
...............................
··
PUB Increment_Display
· waitcnt(625_000 + cnt)
· data.tx($01)
· waitcnt(625_000 + cnt)
· data.tx($00)
· Check_Pins
PUB Decrement_Display
· waitcnt(625_000 + cnt)
· data.tx($02)
· Check_Pins
·
PUB Recieve
·data.start(21,20,%0000,9600)
· REPEAT
·· case data.rx
··· 1: Pixels
··· 2: TestPlay
·
If I wanted to check multiple Pins on my Prop what is the most efficient way to Code ? PUB Check_Pins method is Highlighted below.
Any advise would be appreciated.
...............................................................................................
CON
·_CLKMODE = XTAL1 + PLL1X····· 'External crystal 5MHZ times "1"
·_CLKFREQ = 5_000_000·········· ·'5 Million cycles
OBJ
·DELAY: "Clock"
·DATA: "FullDuplexSerial"
VAR
·long Stack [noparse][[/noparse]9]
·byte Byte_Recieved
·long Input_2
·long Input_3
PUB MAIN
·dira[noparse][[/noparse]0]~~
·dira[noparse][[/noparse]1]~
·dira[noparse][[/noparse]2]~
·dira[noparse][[/noparse]3]~
·data.start(1,0,0,9600)
·Run_Program
PUB Run_Program
·cognew((Check_Pins), @Stack)
...............................
PUB Check_Pins
·Input_2 := INA[noparse][[/noparse]2]
· If Input_2 == 0
·· Increment_Display
· ELSE·······················
·· Check_Pins
...............................
··
PUB Increment_Display
· waitcnt(625_000 + cnt)
· data.tx($01)
· waitcnt(625_000 + cnt)
· data.tx($00)
· Check_Pins
PUB Decrement_Display
· waitcnt(625_000 + cnt)
· data.tx($02)
· Check_Pins
·
PUB Recieve
·data.start(21,20,%0000,9600)
· REPEAT
·· case data.rx
··· 1: Pixels
··· 2: TestPlay
·
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
1) Your Check_Pins routine calls itself and calls Increment_Display which calls Check_Pins. That will cause a stack overflow.
2) Check_Pins runs in its own cog and calls the serial I/O routines. Depending on what your main program is doing, you
may have several cogs calling the serial I/O routines which could cause problems. If this cog is the only one calling the
transmit routines, you may be ok.
I don't know what you're doing with Recieve. It doesn't seem to be called and it reinitializes the serial I/O object.
Run_Program just exits after starting Check_Pins and, after returning to your main routine, "falls off the end" which causes the
main cog to stop.
How about starting with a brief description of what you want to accomplish rather than posting relatively long fragments of code that
can't do anything useful? Then we can point you to possible examples of similar problems that you can start with and modify.
....................................
PUB Check_Pins
· Input_2 := INA[noparse][[/noparse]2]
· If Input_2 == 0
··· Increment_Display
· ELSE·······················
·· ·Check_Pins
....................................
I want to have·8 push buttons connected to 8 seperate IO lines on the Prop. I would like to have a dedicated processor check the status of these inputs constantly and jump to a specific sub-routine for that paticular button press. What would be the most efficient way for the dedicated processor to run in a loop checking the status of all 8 buttons and call methods to handle each one ?
Thanks for the help,
JMLStamp2p
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
What Paul and Mike didn't say so openly is that your code is a total mess! Of course we will help, but it would help you much more if you were working yourself through the tutorials, especialy chapter 3 of the manual - from the beginning to the end!
You want to read the status of an input pin; you do this by INA[noparse][[/noparse]nr_of_pin]; so the simplest way (there are three or four more possibilities) is to check them one ofter the other:
The code as a whole was never intended to run a specific task, my question in general was the highlighted code as you have answered.
Thanks,
JMLStamp2p
PS: I will read chapter 3