membrane in, 7 segment out ...

I am a newbie on my third project, but I am having problems getting the inputs from a membrane ( which I have working ) to make a 7 segment display either increase its count each time one button is pressed, or decreased if the other button is pressed. It must only count up to 9 and then roll over to 0 again ( or 9 when it counts down to 0 )
I need to increase a counter, and then convert it with a lookup table to send serially to a HTC595 to light the correct segments. ( there are 4 such 7 segment displays , and 8 buttons of course )

I am calling one digit GT and have been playing first with getting it to increment when button F is pressed, which it does, but every other button also increments it.......
( The keypad sketch is from one of the examples in the Keypad library )

Once I get this working I still have to work out the lookup table for the serial out.

This is what I am playing with :-

int delay ();
byte rowPins[ROWS] = {7, 6, 5};
byte colPins[COLS] = {8, 9, 10, 11}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad cusomKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup(){
Serial.begin(9600);
}

void loop(){
delay (100); // my crude debounce
char customKey = cusomKeypad.getKey();

if (customKey != NO_KEY){
Serial.println(customKey);
Serial.println(GT);
if (customKey ='F' ) { GT++ ;} }
if (GT==10) { GT=0;}
Serial.println(GT);

}
}

Are you confusing '=' with '=='?

(this is probably not a hardware question)

pS maybe it is my crappy phone browser, but I don't see where GT is declared

Yes I only posted part of the sketch, I have put it all below.
The extra = was in case I had got that wrong and i was worth a try :slight_smile:
I even tried putting the missing t in the cusomkeypad but that didnt help either.

/* @file CustomKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates changing the keypad size and key values.
|| #
*/
#include <Keypad.h>
#include <SPI.h>
int GT = (0);
int GU = (0);
int RT = (0);
int RU = (0);

const byte ROWS = 3; //three rows
const byte COLS = 4; //four columns
//define the symbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {

{'L','K','J','I'},
{'H','G','F','E'},
{'D','C','B','A'}
//on Yebo Electronics membrane 1=A 5=E *=I and so on with bottom pin to 5 and top pin to 11
// 22k pull up resistors on the 3 rows, pin 5,6,7
};

int delay ();
byte rowPins[ROWS] = {7, 6, 5};
byte colPins[COLS] = {8, 9, 10, 11}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad cusomKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup(){
Serial.begin(9600);
}

void loop(){
delay (100); // my crude debounce
char customKey = cusomKeypad.getKey();

if (customKey != NO_KEY){
Serial.println(customKey);
Serial.println(GT);
if (customKey ='F' ) { GT++ ;}
if (GT==10) { GT=0;}
Serial.println(GT);

}
}

'F' is non-zero, so the assignment to customKey will always be true.
I don't think this is what you intended.

Thanks Groove

F ( and all the keys ) are characters so will always be true - I think I have got it

I think I must go back to the simple keypad example, ( which I abandoned when I had a problem caused by my stupidly connecting one of the columns to pin1 while using the serial commands )

I havn't figured out what the "Demonstrates changing the keypad size and key values." is supposed to be, with the Keypad cusomKeypad = Keypad( makeKeymap(hexaKeys),

How can I get a statement to function if say F button has been pressed, It prints out "F" OK.?

So I think I need to work out how to do a boolean function with a character variable ??

and in another example from the library we have :-
void loop()
{
char key = kpd.getKey();
if(key) // same as if(key != NO_KEY)
{
switch (key)

which seems to be doing the same thing,, I am being a bit blonde this morning :-/

So I think I need to work out how to do a boolean function with a character variable ??

No you need to work out that == is a compare and = is an assigment and that if you do

if (customKey ='F' ) { GT++ ;}

you're setting customKey to 'F'.

Korman

Thanks,

I forgot to add the second = again

I will try that

To prevent these kinds of errors, it helps to write: if ('F' == customKey) { ... }

For the compare it makes no difference, but if you miss the second =, the compiler will complain about it.

Korman

Thanks thats a good idea, makes it a bit more foolproof

I have got it all working, even the shiftout to the leds.
I used switch/case to do the incrementing of the counters, and a lookup table from the counters to a binary number representing the LED segments.

That's 3 projects working in my first month, thanks for the advice guys.