reading a 4x4 switch matrix

Status
Not open for further replies.
I ran your suggestion and it doesn't add the 50 for some reason?? I need to investigate further.
 
Please indent and format your code!

Geez oh grief. If 16 is pressed, you ONLY print the key pressed. 50 is being properly added, you just don't show the total.

If any other key is pressed, you ONLY print the total. You don't display what the key press was.


Indenting makes code so much easier to understand. Really. Do it for those who may try to help you in the future. That's not going to be me. I've spent an hour writing your program for you, and at least 10 hours replying to posts here. Probably closer to 30.


Code:
WHILE 1 = 1
    WHILE Keypressed = 0 'print key and exit when key pressed
        Keypressed = Keypad16.Value
        IF Keypressed <> 0 THEN
            IF Keypressed = 16 THEN 'Keypressed = double zero
                    Total = Total + 50   //50 added here for 00
                    WriteAt(1,1,"key pressed =",DecToStr(Keypressed,2))         // double0 = 50
                ELSE
                    Total = Total + Keypressed
                    WriteAt(2,1,"total=",DecToStr(Total,2))        // double0 = 50
            END IF
        END IF
    WEND
    DELAYMS(100)
    WHILE Keypressed <> 0 'loop until key not pressed
        Keypressed = Keypad16.Value
    WEND
WEND
 
You are only updating one line or the other on the LCD depending on which paet of the if/then/else statement is executed.

If you remove the clutter and properly format, this is easy to see.

 
JonSea,

I am impressed with the passion and tenacity you use to address MrDEB's issues.

It is regrettable that MrDEB does not appear as committed to same clarity of expression that you have achieved.

Because of that clarity the examples you have posted are more accessible to MrDEB's level of experience.

The other code examples posted to this thread so far must be too comlpex for MrDEB to find anything that may be useful in his project.
 
MrDEB's trouble is he won't take the time to focus on the program and follow the sequence through the program line by line, step by step. If he had, he would have noticed the total correctly displayed but not the key press through one path of the if/then and exactly the opposite through the other path.

Instead of taking the time and effort to understand why the updated total wasn't displayed when clearly "total = total + 50" was there and must work, he comes up with some whack-a-mole fascination of what's going on.

Then, in frustration, he switches to a completely different version and really screws things up.

He really needs to learn to go step by step, seeing how the values change and the logic flows. When you can't do this, you end up with 15 questions per line of code!
 
Am sorry about not indenting
In my code, it displays the key pressed and the total of all the keys pressed.
The double0 variable is dimensioned to equal 50. Have run the code several times and attempting to get rid of the fluff or not needed junk.
Plus my version loks like it uses less bytes and variables.
 
here is my complete code. Hopefully it is readable
 
I'm done. Not reading another line. I've given you code. I've explained how you ****** it up.

If you're happy with the mess you've slung together, more power to you.

25 lines of code - over 300 posts. What a gigantic waste of my and every one who has tried to help you's time.
 
Last edited by a moderator:
If someone goes out of their way to help you, gives you working code and you change it and **** it up, I suggest you study every word they write when they explain what you did wrong. It's a wonderful thank you for their effort when you don't even attempt to understand the explanation.

How many hours to YOU THINK people have wasted posting here to help you? I want to know if you have any clue the amount of time you've taken from other people.
 
Last edited:
You should probably check your math inthe mess you posted too. That pile of slop isn't going give you the right results. Getting hit by all those canes is going to hurt like hell.

EDIT: The formating of your if/then statement makes my head spin. Your math, while bizarre, is ok.
 
Last edited:


As I said. It makes ALL OF THE EFFORT SEEM SO WORTHWHILE AND APPRECIATED.
 
Sorry Jon, you have been warned many times. However, i do find these train wrecks amusing.

Mike.
Edit, if you hear a quiet chuckle in the background, it's me.
 
If you hear loud cussing, it might be me.

If you hear snickering or a maniacal laugh, it's probably me. Not only is MrDEB's code going to calculate the wrong values, it's probably going to crash when it's needed on those high scores. MrDEB hasn't figured out why words are important.

EDIT: The formating of your if/then statement makes my head spin. Your math, while bizarre, is ok. The other error will show up at the worst possible time.
 
Last edited:
I hate to say this but I think the maths is correct. He adds 50-keypressed before adding keypressed hence cancelling it out.

However, I've never seen such a convoluted way to handle one special case, surely a one liner would suffice. If keypressed = 16 then keypressed = 50.

Mike.
 

Nope. That part is ok. Bizarre, but ok.

It's what happens next that's the problem. Think about what happens next to that special value.

EDIT: The formating of your if/then statement makes my head spin. Your math, while bizarre, is ok.
 
Last edited:
Nope. That part is ok. Bizarre, but ok.

It's what happens next that's the problem. Think about what happens next to that special value.

Hey Mike, on a second...third....fourth look, you are right. His screwball formating of if/then statements makes my head spin, so somethings I get lost.

The other potential error is more insideous, and will show up at the worst possible time.
 
I originally tried if keypressed = 16 then keypressed = 50
but was worried that making keypressed = 50 would make keypressed = 50 from then on.
I tried Mikes suggestion and my concern was incorrect, keypressed went back to correct value.
I originally used WORD instead of BYTE and changed to BYTE but found that the computations won't go over 100 or so. It is now WORD
not sure about the wrong IF THEN statements?
 
MrDEB,

The code you posted is getting astonishingly close to something that may work. Please consider changing how the keypad, LCD and micro-controller are connected as we are not yet close enough t0 500 posts in this thread.

Also keep up the execlent work of stripping all of that useless source code formatting that makes the posted by others so easy to read and understand.
 
It works as is.
As for formatting, I realize it may not be "correct" but at least my code works.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…