Any help would be appreciated

Cdawilliams

New Member
Not sure if anyone can help me but you never know unless you ask so here goes. I'm designing a game for a mini project of mine but have never been very good with the Picaxe software, mainly working in Flowchart mode but still I hit certain snags so was wondering if anyone could help.

Basically this is what I currently have:
http://www.rapidonline.com/Electronic-Components/Integrated-Circuits/PICAXE/28-pin-Project-board/61482/kw/28-Pin

This is the general idea:
A player throws a ball at switches mounted on a case, different switches depend on different scores (similar to the Inner and Outter rings on a Dart Board), the first player to Light up their 4 Outputs (LED's) Wins. HOWEVER - different players can accidentally hit the other players switch making the game in itself a little tricker.

So here's the slightly more technical side, there are 16 switches, 8 of one colour, 8 of another (The two colours represent a different team) - Not sure if its relevant but they are Push-to-Make siwtches.

I also have 8 LED's, again 4 of one colour, 4 of another. Representive of the two different teams.

Below are two images of what it roughly will look like to give a better idea of what I mean:

Top View:


ISO View:


Now the idea is "if" the Outter Switches get hit it lights up 2 LED's of that colour, E.g. If 'green' outter switch is hit then 2 'green' LED's light up and same for red. *Colours may vary but you get the idea*

However "if" the Inner Switches get hit it lights up 1 LED of that colour.

Now so far I've got the basic program, I can make the LED light up if the Input (Switch) is hit and I have programmed a Delay on all as the intention is to hit the switch with a ball that may bounce so I don't wish it active two LED's by hitting the same Switch twice for example.

The start of the program turns all outputs to off which is fine.

The Problem (Sorry if I've bored you):
I think I need some sort of memory log but I'm having an issue with this scenario:
If an Outter Input is Hit, a Single Input lights, however I'm having trouble stacking it.
E.g. Outter Hit + Inner Hit = 3 Outputs Light Up
Outter Hit + Outter Hit = 2 Outputs Light Up
Inner Hit + Inner Hit = 4 Outputs Light Up (Technically a Win)

Now this is where I have been getting stuck, I don't know how to make it so that once an output is hit then another is hit, to make them stack so that 2, 3 or 4 or Active all at once instead of simply replacing the last.

What I have so far: (May be difficult to read)


As I said, as an amateur with Picaxe its been a real road block so any help at all would be greatly appreciated. Also I know its a lot to digest and I have tried to make it as easy as possible in terms of understand to read but if you are finding trouble understand certain aspects just ask and i'll try clarify in hope that someone out there with a much bigger knowledge than myself can help.

Thank you taking the time to listen and even more so if you can help.

Sincerely,

Chris
 

eclectic

Moderator
Chris.
First quick thoughts.
I can't speak Flowchart, just a little bit Of Basic and Manual 2.

Some genuine questions first.
Are A level programs assessed for elegance, or simply for working?

How have you got your input switches wired? Star/Radial/Parallel?
For example, all your Red-inners, Red-outers etc., so that you effectively have just four inputs?

Possible ideas.
You're using a 28 series, so you've got PortC outputs to play with.

You have already started to program the scores.
Have a look at the IF THEN ELSE type commands

-if pin 0 = 1 then redscore = redscore +1

Each colour has FOUR possible output states. 1,2,3, 4 rest and Restart.

So, for each Team-colour, have four sub-procedures, along the lines of

-If Redscore = 1 then gosub Red1

-Red3 : let pins = % .............

-Green2 : let pinsc = %...............

e.
 

Cdawilliams

New Member
Are A level programs assessed for elegance, or simply for working?
Ideally they just have to work, I thought my design was relatively straight forward.

How have you got your input switches wired? Star/Radial/Parallel?
For example, all your Red-inners, Red-outers etc., so that you effectively have just four inputs?
Regarding the Star/Radial/Parallel, I actually don't know the correct terminology so please excuse that part but yes I have 4 inputs, Two Outter Inputs and 2 Inner Inputs, one for each color and position.

Possible ideas.
You're using a 28 series, so you've got PortC outputs to play with.

You have already started to program the scores.
Have a look at the IF THEN ELSE type commands

-if pin 0 = 1 then redscore = redscore +1

Each colour has FOUR possible output states. 1,2,3, 4 rest and Restart.

So, for each Team-colour, have four sub-procedures, along the lines of

-If Redscore = 1 then gosub Red1

-Red3 : let pins = % .............

-Green2 : let pinsc = %...............

e.
We have been looking into sub-procedures as you can see in the Flowchart, however we got stumped onto the stacking issue. As far as I can tell you can't use a "Greater than or Equal to" question.

I'm not that great in terms of basic but what i'm trying to do is basically say:

Input 0 = Outter Red
Input 1 = Inner Red
Input 2 = Outter Green
Input 3 = Inner Green

Now they're all set as Questions, e.g. "Does Pin0 = 1? And like that for the other 3. As soon as an Input is hit it adds 1 or 2 to what we've called "B0".



After they;re been added it then Jumps to my Subroutine:



This then asks does B0=1, if Yes then it finishes, if no then obviously its entered a subroutine for a reason so goes to ask if B0=2.

Now this is where i'm having trouble, still not sure how to say "Ok well i'm set to 1 now so can I add 2 to make 3 Outputs on or will adding 2 to 1 just overite the original 1 and leave with me 2".

Also sorry if I've missed the point completely have read what you wrote through multiple times, but as I said I'm still an amatuer and sturggle to grasp certain concepts and the different terminology. I hope what I just wrote kind of clears up any queries.

Also I sort of got what you mean regarding:
Have a look at the IF THEN ELSE type commands

-if pin 0 = 1 then redscore = redscore +1

Each colour has FOUR possible output states. 1,2,3, 4 rest and Restart.

So, for each Team-colour, have four sub-procedures, along the lines of

-If Redscore = 1 then gosub Red1

-Red3 : let pins = % .............

-Green2 : let pinsc = %...............
Think I just need to expand on that. But I still find it hard in area's to relate whats being said to what i see when i'm trying to programme it.

Again thanks for your help, any more incite into this would be appreciated,

Regards,

Chris
 

eclectic

Moderator
Chris. Thanks for the quick reply.

I think I "know" the answer, but obviously I can't / won't tell you.

Go backwards. Simplify the problem. Use a pencil and paper.

Manual 2 seems to offer many more solutions than does flowcharting.

e.
 

Tom2000

Senior Member
Chris,

If I was going to build one of these, I'd organize the software as follows:

Infrastructure:

- Two scorekeeping registers, one for red, one for green. The contents of these registers will be values between 0 and 4.

- A subroutine that reads the scorekeeping registers and lights the LEDs based on the scores.

- An interrupt routine that monitors all four switch input channels, debounces the switches, and increments the appropriate scorekeeping register

Initialization:

- Set the scorekeeping registers to zero, call LED update subroutine

- Configure the interrupt mask to simultaneously monitor all four switch input channels

Interrupt routine:

- Detect which switch was pushed. Debounce it.

- Increment the appropriate scorekeeping register. (Hint: check the MAX function)

- Re-enable interrupts

Top Loop:

- Call the LED subroutine

- Test each scorekeeping register. If either equals four, jump to your end-of-game routine.

End of game routine:

- Activate the solenoid that dumps a bucket of cold water on the loser.

- Wait for the "New Game" button to be pressed

- Jump to the Initialization routine.


Since you're using a 28X1, you have lots of I/O pins available to you. So, after you prototype your game, you might make it more interesting by changing the score display to a pair of 7 segment LED displays for each player. (Those four digits would require 11 output pins from the 28X1.)

Play for a higher score to win. Perhaps something like 21, with a minimum of a 2-point advange to win, or play beyond 21 until one player gains a 2-point advantage.


Have fun!

Tom
 
Last edited:

Cdawilliams

New Member
eclectic said:
Chris. Thanks for the quick reply.

I think I "know" the answer, but obviously I can't / won't tell you.

Go backwards. Simplify the problem. Use a pencil and paper.

Manual 2 seems to offer many more solutions than does flowcharting.

e.
Thanks for all the help, and I never wanted or expected the direct answer. Just wanted some guidance in overcoming the wall I seemed to have hit.

I originally tried going over on paper as it seemed the most simplist method of drawing out exactly what I needed and how to get there. However going backwards maybe easier.

Tom2000 said:
Chris,

If I was going to build one of these, I'd organize the software as follows:

Infrastructure:

- Two scorekeeping registers, one for red, one for green. The contents of these registers will be values between 0 and 4.

- A subroutine that reads the scorekeeping registers and lights the LEDs based on the scores.

- An interrupt routine that monitors all four switch input channels, debounces the switches, and increments the appropriate scorekeeping register

Initialization:

- Set the scorekeeping registers to zero, call LED update subroutine

- Configure the interrupt mask to simultaneously monitor all four switch input channels

Interrupt routine:

- Detect which switch was pushed. Debounce it.

- Increment the appropriate scorekeeping register. (Hint: check the MAX function)

- Re-enable interrupts

Top Loop:

- Call the LED subroutine

- Test each scorekeeping register. If either equals four, jump to your end-of-game routine.

End of game routine:

- Activate the solenoid that dumps a bucket of cold water on the loser.

- Wait for the "New Game" button to be pressed

- Jump to the Initialization routine.


Since you're using a 28X1, you have lots of I/O pins available to you. So, after you prototype your game, you might make it more interesting by changing the score display to a pair of 7 segment LED displays for each player. (Those four digits would require 11 output pins from the 28X1.)

Play for a higher score to win. Perhaps something like 21, with a minimum of a 2-point advange to win, or play beyond 21 until one player gains a 2-point advantage.


Have fun!

Tom
See I think that was a route I had not explored, or I had accidentally without realising it. Something to register and store the score, I think on the whole I had the same idea, but you clearly understand and know what your talking about where as I seem to be acting on layman's terms. I think the SubRoutine monitoring/registering the Scoring system is where I am currently at a halt. Going to look into it more over the next few days.

All the help so far has been great, I believe being able to write something and plan it out first generally makes it a lot easier.

Obiously if anyone has any more advice they can give then feel free, otherwise thanks Tom and Eclectic for some very helpful advice. Going to try get my head around and implement it at some point.

Kind Regards,

Chris
 

eclectic

Moderator
Chris. I've had a go at translating your flowchart.
This is effectively what you have so far.

main:
IF pin0 = 1 then
b0 = b0 + 1
ELSEIF pin1 = 1 then
b0 = b0 + 2
ELSEIF pin2 = 1 then
b1 = b1 + 1
ELSEIF pin3 = 1 then
b1 = b1+2
ENDIF

b0 is REDscore b1 is GREENscore.
...........................................
Now,
You've got eight LEDs, connected to output pins 0 – 7
Page 96 of Manual 2 gives an example of how Pins= %... operates.

It looks like you have three tasks.
1.Read up on BINARY.
2.Show how two scores can be represented, using these eight bits.
3.Having a play with the simulator.

Task 2 can be accomplished using a pencil and some squared paper.
(And some Junior school arithmetic.)

e.
 
Top