Programming Question
reppig
Posts: 35
I am learning the propeller though a class at school. We are working toward some type of video game. In the steps to that end I wrote a program using some objects found in the object exchange.
The program (below) works as I expected. However, if the reticule gets to the top or left side of the screen it locks up. So, I added the if statements which are commented out, in the enclosed, to prevent the reticule from getting off the screen. If you un-comment the if statements and try to run it - the reticule goes right to the top of the screen and locks up.
What is the problem with the if statements??? I can't figure it out.
All the printing on the screen and waitcnt's were to help debug the problem.
Post Edited (reppig) : 11/5/2009 3:23:27 PM GMT
The program (below) works as I expected. However, if the reticule gets to the top or left side of the screen it locks up. So, I added the if statements which are commented out, in the enclosed, to prevent the reticule from getting off the screen. If you un-comment the if statements and try to run it - the reticule goes right to the top of the screen and locks up.
What is the problem with the if statements??? I can't figure it out.
All the printing on the screen and waitcnt's were to help debug the problem.
CON _clkmode = xtal1 + pll16x ' Set crystal and PLL for 16x operation _xinfreq = 5_000_000 ' Set input crystal value to 5MHz '512x384 tiles = VGA#tiles ' Set tiles for VGA graphics ASM driver object OBJ ADC : "MCP3208" ' Analog to Digital converter driver object VGA : "VGA graphics ASM" ' VGA graphics driver object VAR ' Global variable definitions byte i, x, y long xval,yval long Cursor_x,Cursor_y PUB Main VGA.start ' Start VGA driver VGA.pointcolor(1) ' Set pointcolor which sets the color Foreground=1 or ' Background=0 color for graphics repeat i from 0 to tiles - 1 ' Set tile colors VGA.color(i,$FF00) ' Change this to change screen color $000F = blue (back) ADC.start(14, 13, 15, %0000_0000_0000_0011) ' Start ADC driver start(dpin, cpin, spin, mode) ' dpin = pin connected to both DIN and DOUT on MCP3208 ' cpin = pin connected to CLK on MCP3208 ' spin = pin connected to CS on MCP3208 ' mode = channel enables in bits 0..7, diff mode enables in bits 8..15 waitcnt(clkfreq * 10 + cnt) ' WAIT 10 sec for Monitor to warm up Cursor_x := 256 ' Start in center of the screen. Cursor_y := 192 repeat xval := 511 * ADC.in(0)/ 4096 ' Determine joystick x value and scale for 0 to 511 screen yval := 383 * ADC.in(1)/ 4096 ' Determine joystick y value and scale for 0 to 383 screen yval := 383 - yval ' y needs to be flipped case xval 'Determine which way to move the cursor 384..511 : Cursor_x++ '227..286 : Cursor_x := Cursor_x 0..128 : Cursor_x-- case yval 288..383 : Cursor_y++ '187..197 : Cursor_y := Cursor_y 0..96 : Cursor_y-- VGA.SimpleNum(150,12,Cursor_x,0) VGA.SimpleNum(150,32,Cursor_y,0) { if (Cursor_x >= 400) Cursor_x := 400 if (Cursor_x <= 50) Cursor_x := 50 if (Cursor_y <= 50) Cursor_y := 50 if (Cursor_y >= 333) Cursor_y := 333 } VGA.SimpleNum(464,12,Cursor_x,0) VGA.SimpleNum(464,32,Cursor_y,0) VGA.shape(Cursor_x,Cursor_y,15,15,15,VGA.deg(0)) 'shape(x,y,sizeX,sizeY,sides,rotation) VGA.line((Cursor_x-12),Cursor_y,(Cursor_x+12),Cursor_y) 'Draws line from px,py to dx,dy VGA.line(Cursor_x,(Cursor_y-12),Cursor_x,(Cursor_y+12)) 'Draws line from px,py to dx,dy VGA.clear
Post Edited (reppig) : 11/5/2009 3:23:27 PM GMT
Comments
[noparse][[/noparse] code]
your code
[noparse][[/noparse] /code]
(remove the space from both [noparse][[/noparse] code] blocks.)
It might be an indentation issue, but I can't tell.. [noparse]:)[/noparse]
Also, you might want to add a subject to your message.
(Use the pencil icon in the upper corner of your message to edit it.)
OBC
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?
Visit the: The Propeller Pages @ Warranty Void.
>=··and <=
You should use =>· and =<
Sam
but maybe less understandable for some people
the #> and <# operators do the limiting to a min and max values
Or
you could keep your original case statements BUT instead of the if statments have this
I used >= and <= because that was what was in the Propeller Quick Reference guide in the propeller IDE.
Is it a misprint or does it mean something different my way?? I was trying for less than or equal to
The => means Equal to or greater than
The =< means Equal to or less than
These are the operators you need to use for checking if it is less/greater than or equal to.
The <= is an assignment operation just like using += or -=
So when you say
·· x <= 6·· what will happen is it will compare x to 6 and assign x either·0 or -1 depending on the result.
·· x >= 6·· what will happen is it will compare x to 6 and assign x either·0 or -1 depending on the result.
So when you say
· if x <= 6·
you are not just comparing the x with the 6 you are also changing the value of x....so after you come out of the
if-block x will either be 0 or -1
and that is why you had the cursor stay at the top.
JUST REMEMBER......it is not less/greater than or equal to......it is equal or less/greater than .....ie. =< or =>
NOT· <= or >=
It is different from other languages you may be used to.....BUT....that is how things go.....LEARN
this fact just as you have learned other things about programming............
When you are a programmer you learn to use the language and not be stuck with the fact that
OTHER languages do things differently........just like in HUMAN languages.....why do Germans say Wasser
not Water....it is just the way it is.....why do Italians say Acqua while Spaniards say Agua.....just the way it is...
Sam
Post Edited (SamMishal) : 11/5/2009 7:55:36 PM GMT