If statement
Dinoden
Posts: 19
Hi
I have a quick question on the IF statement. I know how to use it like shown below. But what I am after is to know how to go to another place in a program if the IF statement is true. like with this PIC example " GOTO START" if an IF statement is true. I have downloaded the PE labs fun book and I am using it but no good example.
Sorry if this is basic, but I am very new at spin. I have only worked with the PIC ic's
IF INA [noparse][[/noparse]15]:=1
OutA[noparse][[/noparse]0]:= 1
I would like to change the example above to work like the bottom example
IF INA [noparse][[/noparse]15]:=1
GOTO START
I know this is not the right syntax, but I need something that works like this.
Thanks
I have a quick question on the IF statement. I know how to use it like shown below. But what I am after is to know how to go to another place in a program if the IF statement is true. like with this PIC example " GOTO START" if an IF statement is true. I have downloaded the PE labs fun book and I am using it but no good example.
Sorry if this is basic, but I am very new at spin. I have only worked with the PIC ic's
IF INA [noparse][[/noparse]15]:=1
OutA[noparse][[/noparse]0]:= 1
I would like to change the example above to work like the bottom example
IF INA [noparse][[/noparse]15]:=1
GOTO START
I know this is not the right syntax, but I need something that works like this.
Thanks
Comments
A·Couple of things:
Spin is very indentation specific, for that reason you should use the code buttons so that you may indent properly on the forum.
Also notice that in an IF statement, you must use the " == " operator, for setting the value you would use the " := " operator.
There is also no GOTO function in Spin, you must use a sub-routine instead like this example:
Does that make sense?
Rick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
PrEditor·- Text Editor
NYC Area Prop Club
·
Thanks a lot!
This will keep me going for a while.
You just have to program differently without GOTOs. Use the REPEAT statement for loops and the IF / THEN / ELSE statement for decision making. Do use subroutine (method) calls and RETURNs for encapsulating functionality. You can use the ABORT statement to get out of deep parts of your program, particularly for error exits.
Every little bit helps. Thanks for the tip. I have done hardware design (discreet ic's) pretty much my whole professional career, but I sure like how software / processors can reduce a circuit down to practically nothing.
I am really enjoying this new to me Propeller!
Thanks
I just wanted to share one of my biggest PIC18F452 projects. I know it is not Propeller, but I probably will do another large project with the Propeller when I become fluent with it.
Thinking laterally here, wouldn't it be just cool to use a Propeller to drive some old-school 16 segment alphanumeric led displays for a pinball machine.
Re GOTO, pic basic and other forms of basic kind of force you to use GOTO. There is a concept called structured programming and it was well established before the 1980s so it has been around for a long time, which says you can write anything without GOTO. It takes a little getting used to, but it leads to the idea of "top down programming".
I tend to find programs are one of two types - run once then end, or run forever.
run once:
and run forever (in a basic form)
that is the 'top' bit of top down programming as subroutine1 has not been written yet but you have a vague idea that it is going to flash a led or something.
then add a condition to it
Then translate that to spin. Going from Basic to Spin I find there are some key things to watch :=,== and = as they all crop up in spin but in basic they are all =
And there is no 'end' to statements. eg in C you put { then } to signify the end of a block of code. In structured basic languages (sbasic, vb.net etc) you might have 'end' or 'end if' or 'repeat... until' or 'while... wend'. And in between those you put proper indenting because it looks better that way. In spin, the indenting is the essential part of the language. So change
becomes
And the end of the indenting is the indicator the same as } or 'end' or 'endif'
What is the project you are working on?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.smarthome.viviti.com/propeller
Post Edited (Dr_Acula) : 2/3/2010 2:03:14 AM GMT
Yes, I built this 1/2 scale pinball. I built the cabinet, all circuit boards & PIC programming. It took me about a year to complete. I love it! Works great!
I have run vacuum fluorescent alphanumeric displays from discarded microwave ovens / VCR's with PIC's. Very neat.
But right now I don't really have a project in mind for the Propeller. I want to learn this chip because I see so many advantages with the independent cogs, speed(80MHz) etc.
My project will probably lean towards gaming of course. I love building games! I also built a video slot machine a few years ago on a small 7" colour CRT I salvaged. I used the STV5730 OSD for the video display.
Anyway, my propeller is now running a 5X7 matrix which I am going to make a simple game to start learning the Propeller. There is a small "ship" 4 pixels, which I am going to make fire, different leds lighting up as it leaves the ship. The ship can move left to right and falling targets will fall (individual leds). This may seem easy to all you pros, but for my first self made propeller "tutorial" it's been a bit of a challenge. I can't wait to figure this thing out.
Nice talking to you.