A Tricky Project

randomcows

New Member
I'm creating a project in Design Tech which is basically a "Follow Me" game where a sequence of lights is shown and must be copied to eventually win a prize (sweets). Every time the sequence is copied correctly an extra light is added to the sequence starting at 1. My problem is choosing a random number or numbers and storing it so that I can then check the value with the sequence entered by the user. (e.g. creating an array of numbers)

I have the use of a PIC-18 chip and 6 leds with their corresponding PTM buttons.

If anyone can point me in the right direction with a simple example I would appreciate it.

Thanks in advance,
Michael

Edited by - randomcows on 21/09/2006 23:05:47
 

manuka

Senior Member
Isn't this akin to the classic <b>&quot;Simon Says&quot; </b> already &quot;Picaxed&quot; by Rev.Ed ?
 

randomcows

New Member
That simon says kit only seems to have 4 buttons, my project requires 6. Besides, I enjoy the challenge of making the most complex thing in the class! :p
 

thelabwiz

Senior Member
You could store the values as separate bytes in EEPROM (see read &amp; write commands).

Since you plan to use values from 1 to 6, you could store the values in RAM. A value from 1 to 6 only requires 3 bits for storage, allowing you to store two values in one byte.
&lt;air code - to demonstrate concept - not tested&gt;
b0 = first_value
b0 = b0 + (second_value * 8) 'shift left 3 bits
b1 = third_value
b1 = b1 + (fourth_value * 8)
b2 = fifth_value
b2 = b2 + (sixth_value * 8)
That stores the 6 values in 3 bytes.

Extracting the values is also simple.
first_value = b0 AND 7 'read first 3 bits
second_value = b0 / 8 'shift right 3 bits

If you choose to pack the values, be sure to add good comments - or you won't remember what you did.

John
 

randomcows

New Member
The number of stored values will be increasing each time. For example at the start of the game only one light is shown. Then if the sequence is copied correctly then number of lights in the sequence could potentially go to infinity. Could anyone tell me the maximum number of light values I could store on a PIC-18 chip.

Thanks again,
Michael
 

eclectic

Moderator
Michael (randomcows)
Follow Stan and Michael2727's suggestions.

Have a look at AXE106.pdf
(it's in Home / datasheets/ all PICAXE datasheets)

There's a fully documented program
on pages 5 - 8

e.

Edited by - eclectic on 22/09/2006 13:48:34
 

Mycroft2152

Senior Member
Ever wonder how many steps a commercial SIMON game has?

I always thought it would be an interesting project to have a PICAXE play against the SIMON.

Hmmm, let's see 4 LDRs, 4 relays (or 1 4066 chip)....

MycHolmes
 

Technical

Technical Support
Staff member
Infinity may be a bit too much, most people can't manage past 10 on the Simon Says game!!!
 

thelabwiz

Senior Member
Availble memory for storage depends on which version of the 18 you are using.

18: 128 bytes - program size
18A: 256 bytes - program size
18X: 2048 bytes - program size

There are also at least 32 bytes of Special Function Registers (SFR) available via PEEK and POKE.

With the 18A and 18X, you also have 256 bytes of EEPROM.

With the 18X, you can use an external I2C memory chip (whatever size your budget allows).

John
 

hippy

Ex-Staff (retired)
All PICAXE except the 08 have usable RAM (SFR) at $50-$7F giving 48 bytes of sequence, and PEEK and POKE can be used to emulate arrays, for example, in pseudo-code ...

- DIM whichLight[ 0 TO 47 ]
-
- FOR shichStep = 0 TO maxStep
- whichLight[whichStep] = randomNumber
- NEXT
-
- FOR step = 0 TO maxStep
- stepExpected = whichLight[whichStep]
- NEXT

on a PICAXE can become ...

- FOR whichStep = 0 TO maxStep
- arrayPtr = whichStep + $50
- POKE arrayPtr, randomNumber
- NEXT
-
- FOR whichStep = 0 TO maxStep
- arrayPtr = whichStep + $50
- PEEK arrayPtr, stepExpected
- NEXT

Once you have array handling mastered, Simon Says type games should become quite straight forward.

Getting to grips with array handling is also the basis for more complex games such as noughts and crosses ( tic-tac-toe ), battleships, 'go' or even chess. Two-dimensional arrays are not much harder to implement than single dimension ones ...

- DIM myArray[ 0 TO A, 0 TO B ]
- myArray[x,y] = n
- m = myArray[x,y]

can be ...

- arrayPtr = B+1 * x + y + $50
- POKE arrayPtr, n

- arrayPtr = B+1 * x + y + $50
- PEEK arrayPtr, m
 

randomcows

New Member
I have had a look at AXE106.pdf and it seems very useful. -- Thanks eclectic.

It shouldn't be too hard to modify the code to suit my needs so this thread can be considered closed.

Thanks to all who helped out,
Michael
 
Top