Not what you want but you could use a LOOKUP table after the random number is generated.how can I generate a random number as a string?
Not what you want but you could use a LOOKUP table after the random number is generated.how can I generate a random number as a string?
Dave
Always wear safety glasses while programming.
Thanks Dave, Glad someone is watching "me". I am always worried I will misguide him, and no one will be watching.
Anyway, Go back and look at post 7 I think. Now that you and I both understand you will be using strings, (I assumed this the whole time, my bad), it may make more sense to you. The first part shows the quickest way I know of to shift the array. And at the same time check for losing. in my example, only t(0)-t(4) are displayed. t(5) is the you lose check.
The second part shows 1 way to check for a hit, then adjust the array.
I agree with Dave, use a lookup to match a number with a string.
-Bert
The glass is not half full or half empty, Its twice as big as needed for the job!
http://foamcasualty.com/ - Warbird R/C scratch building with foam!
Hey guys, thanks for the support before...
I was indeed heading down the wrong path with my approachesin the end I just put the Ascii equivilents of the numbers 0-9 and "n" into the array instead of trying to tell the LCD to display the Decimal values...
MUCH EASIER
Timing is a bit of a pain, since the main loop counts and GoSub's to other areas (this adds about half a second to the count sometimes) but I'm working on that.
Guess my main problem is my habit of keep looking at "visual" syntax as a reference, since everything appears to run simultaniously... where as on this its loops in loops all the time hehe.
EDIT: Now that I have that sorted, once the code is working and bugs ironed out I will rename the variables to something that makes sense to others reading it and upload the source with the hardware layout for those interested.
COOL!!!
I am looking forward to seeing/playing it. could use a little fun!
Dave
Always wear safety glasses while programming.
Hi,
I seem to have hit a bit of a problem, when I compile the code everything is fine it shows 0 errors 0 warnings but 2 suppressed (cant seem to get any output on these).
However when I go to program the PIC with the compiled code it just loops forever on programming and will not actually write to the PIC.
I have checked all settings including con bits all is fine, I had an issue like this before when i placed a return in the code without anything to return to but that is no longer the case... I am stuck
EDIT: Nevermind power ran out on the pack powering the board![]()
Last edited by UKIkarus; - 7th October 2010 at 15:47.
Hi Guys,
According to the manual, the "BUTTON" function acts as a "GOTO" to a defined label (the last argument) with the added bonus of disabling auto-repeat and or debounce... does anybody know if the same can be used to GOSUB?
or know of a solution to do the same?
Since I have loops within loops the button presses keep being registered, but I cannot use the BUTTON function to GOTO since it will reset the count on the main loop
As you can see I am using GOSUB as to not interrupt the "for..next" loop doing the count, but I need a way of stopping auto repeat on the button checks... (without pausing since this messes up the count timing) unless there is another way to have a definitive count?Code:MAIN: FOR CNT2 = 1 TO CNT IF PORTA.3 = 1 THEN GOSUB SHIP IF PORTA.0 = 1 THEN GOSUB FIRE IF CNT2 == CNT THEN GOSUB ADD GOSUB LCDUPDATE PAUSE 5 NEXT GOTO MAIN
(watchdog timer perhaps? never used it)
Basically so that when the user presses the button it will only increment by 1 and not auto repeat (due to the instructions per second) and increment by about 70 per press
Any help will be greatly appreciated!
To make the button gosub instead of goto to, 1 solution is :
As for the multi press and the way you are doing it, you have to check for when the button is released also. So when you have a button press, set a flag, then next time through the loop, if the flag is set, ignore the press. when the button is released, clear the flag.Code:main button goto no_ship 'if button is NOT pressed, skip the gosub gosub ship ' if button was pressed gosub and return no_ship button goto no_fire gosub fire no_fire .... goto main
If cnt2==cnt gosub add
you can move this line outside of the for next loop. It will be true each time the loop counts to cnt. so just process it before jumping back to main.
as for the counting, you could use a timer setup as a counter. Just load it with a number, then in your mainloop check for an overflow. If it did, call your add. This way, as the levels get harder, just change the preload for the timer.
Last edited by cncmachineguy; - 7th October 2010 at 18:31.
-Bert
The glass is not half full or half empty, Its twice as big as needed for the job!
http://foamcasualty.com/ - Warbird R/C scratch building with foam!
Bookmarks