Notifications
Clear all

Keypad control not working

156 Posts
3 Users
24 Reactions
9,653 Views
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2538
 

@kobusven95 

First mistake I see is that the GetNumber() routine is using "=" instead of "==" to test for equality.

It seems to be a recurring problem, so you should do a search for "if(" and change all of the (assignment) "=" to (logical test) "==".

Also, you keep using the form "if( condition );". that semicolon will probably end the statement and the if, so the part you meant to be executed on condition will ALWAYS be executed.

So, while you're looking at those if statements above, get rid of the semicolons too.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2538
 

@kobusven95 

Noooooooooooooo !!!

Please don't break it down into bits. If it's easier, just drag the source code onto the reply box to include it as a file instead of pasting it directly into the box.

It's important to see everything to trace values ad definitions, so we need all of it.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@kobusven95)
Member
Joined: 2 years ago
Posts: 60
Topic starter  

I see the stepper also work, wont break it down. Promise.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2538
 

@kobusven95 

I now realize that the "if( xxx ) ;" should've been if( xxx ) {" in some cases.

The "switch" statements for num and confkey are not required. You never use any "case:" components and seem to always be using if statements instead. That's not a problem, but you may as well remove the switch staments from the sketch.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2538
 

@kobusven95 

When you have the changes made and it compiles, test each of the control keys in sequence and send me another report if one isn't recognized or doesn't work. We'll proceed in small steps.

Meanwhile, I'm going to look at ways to reduce the volume of code with an eye to making it easier to add new stuff or modify it in the future.

 

By the way - what are you running this on ?

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@kobusven95)
Member
Joined: 2 years ago
Posts: 60
Topic starter  

@will Already done. compiles 100%, but somewhere there is till a loop error. It starts and asks for the first number, but then goes into the loop.

By the way - what are you running this on ? - A mega 2560.

Just curios - I wanted to use a 3.2" opens-smart tft, but could not get it working on the Mega, I also struggled to get the 2.4", working on the mega - seems the only working library is the <MCUFRIEND_kbv.h> (modified some pins) I cannot get the other display to initialize - even with this library. I will upload now.


   
ReplyQuote
(@kobusven95)
Member
Joined: 2 years ago
Posts: 60
Topic starter  

   
ReplyQuote
(@kobusven95)
Member
Joined: 2 years ago
Posts: 60
Topic starter  

   
ReplyQuote
(@kobusven95)
Member
Joined: 2 years ago
Posts: 60
Topic starter  

It only shows the first initialized screen... To select...


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2538
 

@kobusven95 

What's the difference between (int) num (=kpd.getKey()" and (String) confkey (=kpd.getKey()) ?

You read it once as a number and then again as a String.

I am confused by your erratic nesting level ... for instance, you seem to be declaring a String function in the middle of an if statement clause ?

By the way, you don't seem to have finished cleaning up changing the assignments to logical testing. See line

 if (confkey='C');                             // Confirm selection

in the above sketch segment.

 

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@kobusven95)
Member
Joined: 2 years ago
Posts: 60
Topic starter  

@will, what I want to do is to get the number (single digit), between 0 and 9, display whatever should be displayed and confirm the selection with "C".


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2538
 

@kobusven95 

But you seem to be reading both from the same source.

Copy the following function to the area where you have your other routines ...

//
//      Confirm a command
//
bool confirmCommand() {
    int theKey = NO_KEY;                    /// Nothing read yet
    //
    while (theKey==NO_KEY)
        theKey = kpd.getKey();              // keep reading until user responds
    //
    return (theKey=='c' || theKey=='C');    // Confirmed if user entered cor C
}

 And then go through your sketch and use "if ( !confirmCommand() ) break;" everywhere you want to confirm a selection. It keeps calling kpd.getKey() until it gets a keypress and then returns whether it was a confirmation or not. If NOT confirmed, this should break out to the next higher level of nesting.

This will also remove a fair amount of repeated code and make it easier to follow.

 

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@kobusven95)
Member
Joined: 2 years ago
Posts: 60
Topic starter  

@will, the flow should be:

initialize  everything

wait for keypad input

according to the input, display different strings, and confirm the selection with a C


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2538
 

Anything seems possible when you don't know what you're talking about.


   
kobusven95 reacted
ReplyQuote
(@kobusven95)
Member
Joined: 2 years ago
Posts: 60
Topic starter  

@will - just to confirm - I get the following error..

tft.setColor(BLUE); // Set to desired colour (changed "color" to "BLUE"

Blue is defined

#define BLUE 0x001F

error:

'class MCUFRIEND_kbv' has no member named 'setColor'; did you mean 'setCursor'?

 


   
ReplyQuote
Page 2 / 11