Go Down

Topic: Matrix Keypad - Optimisation (Read 7455 times) previous topic - next topic

robtillaart

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.

Rob Tillaart

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

Carl R

#46
Dec 02, 2010, 08:36 pm Last Edit: Dec 02, 2010, 08:47 pm by Deep_C Reason: 1
single quotes worked, thanks

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

Code: [Select]
 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)

robtillaart

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



Rob Tillaart

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

CrossRoads

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)?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Carl R

yeah the single quotes worked on case

rob- thanks for the disambiguation

-carl

Go Up