Go Down

Topic: membrane in, 7 segment out ... (Read 1 time) previous topic - next topic

Boffin1

Sep 25, 2010, 11:33 pm Last Edit: Sep 25, 2010, 11:34 pm by John_Smith Reason: 1
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);
 
 }
}

Groove

#1
Sep 25, 2010, 11:48 pm Last Edit: Sep 25, 2010, 11:55 pm by GrooveFlotilla Reason: 1
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
Per Arduino ad Astra

Boffin1

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 :-)
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);
 
 }
}


Groove

#3
Sep 26, 2010, 12:17 am Last Edit: Sep 26, 2010, 12:19 am by GrooveFlotilla Reason: 1
'F' is non-zero, so the assignment to customKey will always be true.
I don't think this is what you intended.
Per Arduino ad Astra

Boffin1

#4
Sep 26, 2010, 07:55 am Last Edit: Sep 26, 2010, 09:00 am by John_Smith Reason: 1
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.?



Boffin1

#5
Sep 26, 2010, 09:01 am Last Edit: Sep 26, 2010, 10:45 am by John_Smith Reason: 1
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  :-/

Korman

#6
Sep 26, 2010, 09:22 am Last Edit: Sep 26, 2010, 09:23 am by Korman Reason: 1
Quote
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

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


you're setting customKey to 'F'.

Korman

Boffin1

#7
Sep 26, 2010, 10:47 am Last Edit: Sep 26, 2010, 10:58 am by John_Smith Reason: 1
Thanks,

I forgot to add the second = again

I will try that

Korman

#8
Sep 26, 2010, 11:05 am Last Edit: Sep 26, 2010, 11:05 am by Korman Reason: 1
To prevent these kinds of errors, it helps to write:
Code: [Select]
if ('F' == customKey) { ... }

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

Korman

Boffin1

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

Boffin1

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.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy