• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

input and save input

be80be

Well-Known Member
I played with this and C using the xc8 I kind like it. The arduino has map which is great for mapping adc I soldered up 5 buttons just for fun and mapped the reading to player 1 2 3 4 5 I still say that would be the way to go you log say who hit the button first there no problem finding that out. I'm sure it not talk 10 minutes to write map for swordfish.

Like been said you got figur how to not use a delay because the LEDs in matrices going to blink.
case to handle the if and ands of the game.
 

Pommie

Well-Known Member
Most Helpful Member
If you use an ADC ladder for the switches then when more than 1 switch is pressed it will fail and in a "fastest finger first" situation you can guarantee more that one switch will be pressed.

Mike.
 

be80be

Well-Known Member
I played with it a bit it's really fast if you use the map like arduino has they show the function.
it get's the presses I've seen ladders used in games I don't think 8 people will hit the button at time.

Here a screen shot I press the buttons as fast I could it picked them up in good order.
Screenshot from 2017-11-25 01-35-59.png
I pressed 4 and 5 as close as i could to same time it got the one i pressed first the map function works good.
I tried them all looks like player 3 wanted the game.

Code:
long map(long x, long in_min, long in_max, long out_min, long out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
 
Last edited:

JonSea

Well-Known Member
If you use an ADC ladder for the switches then when more than 1 switch is pressed it will fail and in a "fastest finger first" situation you can guarantee more that one switch will be pressed.

Mike.
Since MrDEB hasn't explained the game play or almost anything he's trying to do, there's no way to know if speed is part of game play.
 

be80be

Well-Known Member
This more fun then learning ltspice. I've been playing a buch with buttons I made a 12 button matrices and ladder played with the output going to serial comport and the ladder seems to work just as good and less error then the matrices.

But now if I don't use map and use a bunch of if thens to catch the adc reading the ladder sucks.
 
Last edited:

Pommie

Well-Known Member
Most Helpful Member
Assuming the resistors in the switch ladder are all the same can't you just add and divide? EG, if 10 resistors from Vdd to GND and switches from each junction to the adc pin then the top one will be 1024 and the bottom ≈ 102 , so add 50 and divide by 102 should give the switch number (0 or 1 to 10) - assuming very high resistor as pull down. Or did I miss something?

Mike.
 
Would a select / case work?
SELECT-CASE is really just another way of saying IF-THEN-ELSEIF-THEN-ELSE. It usually translates into the exact same code either way.
It reads a lot easier though!

Mike's suggestion is probably easier/quicker than using 'map'.
 

MrDEB

Well-Known Member
Thread starter #111
I researched using an ADC /resistor ladder but this is a battery operated game and as the battery voltage decreases would this not throw the ADC out the window??
I like the idea and did some research over at EDN about resistor ladders and numerous ways to achieve.
The idea of using a 44+ pic scares me about soldering them. Goiing to look at micro chip and see if they have a different footprint. If not then back to a matrix.
 

MrDEB

Well-Known Member
Thread starter #112
Here is a description of the game
Game description

up to 10 players

game starts when a player (player #1)has a double domino that is needed to start.

Player#1 depresses his / her button, this turns on their Position Led and this starts a countdown timer of 3 green LEDs, two yellow then 1 red LED. When the Red LED is turned on then the players (player #1) turn is over.

Player #2 has his / her Position Led comes on when player #1 is done with their turn to indicate it is their turn to play(player #2). Player must complete their play before the count down timer times out.

The position Leds come on to indicate it is that players turn to play. The Position leds do not just go 1, 2, 3, etc. The player positions are saved within the pic code at the beginning of the game before actual game play begins.
 
but this is a battery operated game and as the battery voltage decreases would this not throw the ADC out the window??
I know this isn't going to make a lick of sense, but if the ADC reference voltage is the supply voltage (VDD) then as the battery drops (VDD) the reference drops too.

The ADC readings stay the same since they're relative to the reference voltage.
 

JonSea

Well-Known Member
So:

1. At start of game each player presses a button to indication which positions are in use.

2. Game starts when player 1 presses his button.
□ Why must you start with pjayer 1?

3. Timer counts down shown by a few LEDs. Red LED equals turn over.
□ What happens if player finishes before red LED is illuminated? No provision to end turn early?

4. Next player LED illuminates and the countdown commenses.

So you have 10 - 12 player switches and supporting hardware that are only used at the beginning of the game to show if a position is active?

Suggestions:

Selecting player positions: Use a single button for player election. Flash each player LED for several seconds in turn during which time the ELECT button may be pressed to include that position. Continue flashing only positions that have not been elected until the BEGIN button is pressed.

Start the game by illuminating a random player LED and start the timer. Display the countdown LEDs. Move to next position when DONE switch is pressed or timer times out.

Play pauses when the PAUSE/CONTINUE button is pressed for a bathroom break.

Let's see:

10 player LEDs, only one of which is illuminated at a time.

4 or 5 countdown LEDs and a pause LED, only one of which is illuminated at a time.

4 push buttons, only one of which is pressed at a time.

Seems pretty simple.

I would probably use a brute force approach.

Dim Player1 as boolean
Dim Player2 as booleen



Dim Player10 as boolean

If PlayerN = true, that position is in use.

If you can have a boolean array (I don't know), even easier.

Why are we on 6 pages with a 40 pin PIC? This sounds like an exercise for Computers 101.
 

JonSea

Well-Known Member
I know this isn't going to make a lick of sense, but if the ADC reference voltage is the supply voltage (VDD) then as the battery drops (VDD) the reference drops too.

The ADC readings stay the same since they're relative to the reference voltage.

MrDEB should direct his research to ratiometric.
 

MrDEB

Well-Known Member
Thread starter #117
wasn't sure if the ADC used the battery voltage as a reference. Then the resistor ladder might be the ticket.
3. Timer counts down shown by a few LEDs. Red LED equals turn over.
□ What happens if player finishes before red LED is illuminated? No provision to end turn early?
when player has finished their turn he / she presses their position button and next player's position led is ON and countdown is stared.
It sounds like I need to read up on boolean.
As for a pot, I have a routine that counts down the time and is set at the beginning of the game. An LED flashes as to selected time interval
1 blink = 1 seconds, 2 blinks = 2 seconds, 3 blinks = 3 seconds between enabled leds (G, G, G, Y, Y, R so 1 blink a player has 5 seconds to finish their play) no need for a pot but it would make adjusting the count down timer easier.
 

MrDEB

Well-Known Member
Thread starter #118
Finally got back to this project design.
Decided to use the ADC on portA.0 and A.1 for the 10 switches
Looking at using A.2 for the game selection option to free up an additional pin.
Here is a schematic for the resistor ladders. In simulation I have a voltage span of 4.17v to 2.5v. IMO plenty of range to distinguish between button depresses. Only one press at a time anyway.
One issue that may arise is taking the port input to a logic level different than 55uv. Have parts ordered to actually build the ladders using 1% resistors
 

Attachments

Latest threads

EE World Online Articles

Loading

 
Top