Pages: 1 2 3 [4]   Go Down
Author Topic: Matrix Keypad - Optimisation  (Read 6656 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13739
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

case "a":  ==> case 'a':
you must use single quotes, otherwise it is a string and the case will use the address of the string or so.

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

AZ
Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
Effectiveness is the measure of truth
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

single quotes worked, thanks

I still don't get the fuction of this code:

Code:
 int k = kbValue(keyboardValue);   // maps the value of the key being pressed "keypressed" i.e. 0-9
  
  Serial.println(k);                // print the value back to the Serial view window on your PC
  delay(1000);
}

// interpret the keyboard routine
int kbValue(int kbv)
« Last Edit: December 02, 2010, 02:47:42 pm by Deep_C » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13739
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

int k = kbValue(keyboardValue);

in plain English: kbValue() will do a lookup of keyboardValue (the parameter passed) and returns a value 0..16 to indicate the keypressed. This return value is assigned to the var k.

The names are a bit misleading here. Better names could be

- int rawKeyPressed = analogread(A0);  
- int key = ConvertRawToKey(rawKeyPressed);  
- switch(key)

etc



Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27115
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

try just single quotes, not double. Think you have to decide on one other  - is keypressed going to by type char, or type int (or byte)?
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

AZ
Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
Effectiveness is the measure of truth
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yeah the single quotes worked on case

rob- thanks for the disambiguation

-carl
Logged

Pages: 1 2 3 [4]   Go Up
Jump to: