Pages: [1]   Go Down
Author Topic: membrane in, 7 segment out ...  (Read 1147 times)
0 Members and 1 Guest are viewing this topic.
Cape Town South Africa
Online Online
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
  
  }
}
« Last Edit: September 25, 2010, 04:34:38 pm by John_Smith » Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: September 25, 2010, 04:55:19 pm by GrooveFlotilla » Logged

Per Arduino ad Astra

Cape Town South Africa
Online Online
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

'F' is non-zero, so the assignment to customKey will always be true.
I don't think this is what you intended.
« Last Edit: September 25, 2010, 05:19:11 pm by GrooveFlotilla » Logged

Per Arduino ad Astra

Cape Town South Africa
Online Online
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.?


« Last Edit: September 26, 2010, 02:00:05 am by John_Smith » Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

Cape Town South Africa
Online Online
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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  :-/
« Last Edit: September 26, 2010, 03:45:09 am by John_Smith » Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

Central Europe
Offline Offline
Edison Member
*
Karma: 7
Posts: 1220
Use the Source, Luke.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: September 26, 2010, 02:23:54 am by Korman » Logged

Cape Town South Africa
Online Online
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks,

I forgot to add the second = again

I will try that
« Last Edit: September 26, 2010, 03:58:13 am by John_Smith » Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

Central Europe
Offline Offline
Edison Member
*
Karma: 7
Posts: 1220
Use the Source, Luke.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Korman
« Last Edit: September 26, 2010, 04:05:39 am by Korman » Logged

Cape Town South Africa
Online Online
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

With my mobile phone I can call people and talk to them -  how smart can you get ?

Cape Town South Africa
Online Online
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

Pages: [1]   Go Up
Jump to: