Pages: [1]   Go Down
Author Topic: 3x4 keypad for android phones using Bluetooth shield  (Read 730 times)
0 Members and 1 Guest are viewing this topic.
Philippines
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm trying to modify this tutorial http://sunraysme.wordpress.com/2012/04/10/a-keypad-for-thearduino/
Instead of using LCD Display, I am using Blutooth shield and arduino atmega 328 and an  Android 2.3 phone with Bluetooth SPP application.
I tried to modify the code in the tutorial to this
Code:
#include <SoftwareSerial.h>
#include <Keypad.h>
SoftwareSerial mySerial(2, 3);

/**********************************************************************/
// start of creating the keypad//
const byte ROWS = 4; //Four rows//
const byte COLS = 3; //Three columns//
char keys[ROWS][COLS] = { {’1′,’2′,’3′}, {’4′,’5′,’6′}, {’7′,’8′,’9′}, {‘#’,’0′,’*′} };


byte rowPins[ROWS] = { 5, 10, 9, 7 };// Connect keypad ROW1, ROW2, ROW3 and ROW4 to these Arduino pins//
byte colPins[COLS] = { 4, 6, 8 }; // Connect keypad COL1, COL2 and COL3 to these Arduino pins//
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );//end of creating the Keypad//
/**********************************************************************/

void setup()
{

pinMode (4, INPUT);//Column 1
pinMode (6, INPUT);//Column 2
pinMode (8, INPUT);//Column 3
digitalWrite(4, HIGH);//Pull up resistor of Arduino
digitalWrite(6, HIGH);// Pull up resistor of Arduino
digitalWrite(8, HIGH);// Pull up resistor of Arduino
Serial.print(“The Keypad Test”);
delay(1000);

}

void loop()
{
char key = keypad.getKey();
if (key != NO_KEY)
{
Serial.print(key);
delay(100);
}
}
/**********************************************************************/


but when i try to compile it these errors always show up
 "_3x4_keypad_trial:8: error: expected `}' before 'u2032'
_3x4_keypad_trial:8: error: expected `}' before 'u2032'
_3x4_keypad_trial:8: error: expected ',' or ';' before 'u2032'
_3x4_keypad_trial:8: error: expected declaration before '}' token"

what do they mean? i tried to use all the given characters and it still appears.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49270
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You copied and pasted that code from a web site, right? The quotes on the key definition line are wrong. Some are forward quotes; some are backwards quotes.

Some of the double quotes are wrong, too.

Replace all the ' and ", and the code compiles, at least on 1.0.1.
Logged

Philippines
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have changed it to this
Code:
#include <SoftwareSerial.h>
#include <Keypad.h>
SoftwareSerial mySerial(2, 3);

/**********************************************************************/
// start of creating the keypad//
const byte ROWS = 4; //Four rows//
const byte COLS = 3; //Three columns//
char keys[ROWS][COLS] =
{
{"1","2","3"},
{"4","5","6"},
{"7","8","9"},
{"#","0","*"}
};

byte rowPins[ROWS] = { 5, 10, 9, 7 };// Connect keypad ROW1, ROW2, ROW3 and ROW4 to these Arduino pins//
byte colPins[COLS] = { 4, 6, 8 }; // Connect keypad COL1, COL2 and COL3 to these Arduino pins//
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );//end of creating the Keypad//
/**********************************************************************/

void setup()
{

pinMode (4, INPUT);//Column 1
pinMode (6, INPUT);//Column 2
pinMode (8, INPUT);//Column 3
digitalWrite(4, HIGH);//Pull up resistor of Arduino
digitalWrite(6, HIGH);// Pull up resistor of Arduino
digitalWrite(8, HIGH);// Pull up resistor of Arduino
Serial.begin(9600);
Serial.println("The Keypad Test");
delay(1000);

}

void loop()
{
char key = keypad.getKey();
if (key != NO_KEY)
{
Serial.begin(9600);
Serial.println(key);
delay(100);
}
}
/**********************************************************************/

I can still got errors, but this time it says


"_3x4_keypad_trial:14: error: too many initializers for 'char [3]'
_3x4_keypad_trial:14: error: too many initializers for 'char [3]'
_3x4_keypad_trial:14: error: too many initializers for 'char [3]'
_3x4_keypad_trial:14: error: too many initializers for 'char [3]'
_3x4_keypad_trial:18: error: 'Keypad' does not name a type
_3x4_keypad_trial.cpp: In function 'void loop()':
_3x4_keypad_trial:38: error: 'keypad' was not declared in this scope
_3x4_keypad_trial:39: error: 'NO_KEY' was not declared in this scope
"
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49270
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
char keys[ROWS][COLS] =
{
{"1","2","3"},
{"4","5","6"},
{"7","8","9"},
{"#","0","*"}
};
Why did you change the single quotes to double quotes? Change them back.
Logged

Philippines
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have change them back the errors are now the same as the first one
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49270
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This code:
Code:
#include <SoftwareSerial.h>
#include <Keypad.h>
SoftwareSerial mySerial(2, 3);

/**********************************************************************/
// start of creating the keypad//
const byte ROWS = 4; //Four rows//
const byte COLS = 3; //Three columns//
char keys[ROWS][COLS] =
{
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'#','0','*'}
};

byte rowPins[ROWS] = { 5, 10, 9, 7 };// Connect keypad ROW1, ROW2, ROW3 and ROW4 to these Arduino pins//
byte colPins[COLS] = { 4, 6, 8 }; // Connect keypad COL1, COL2 and COL3 to these Arduino pins//
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );//end of creating the Keypad//
/**********************************************************************/

void setup()
{

pinMode (4, INPUT);//Column 1
pinMode (6, INPUT);//Column 2
pinMode (8, INPUT);//Column 3
digitalWrite(4, HIGH);//Pull up resistor of Arduino
digitalWrite(6, HIGH);// Pull up resistor of Arduino
digitalWrite(8, HIGH);// Pull up resistor of Arduino
Serial.begin(9600);
Serial.println("The Keypad Test");
delay(1000);

}

void loop()
{
char key = keypad.getKey();
if (key != NO_KEY)
{
Serial.begin(9600);
Serial.println(key);
delay(100);
}
}
/**********************************************************************/

produces this "error":

Quote
Binary sketch size: 8,528 bytes (of a 28,672 byte maximum)
Logged

Philippines
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've got all the codes correct and I will try to apply its concept in my prevoius post which is http://arduino.cc/forum/index.php/topic,138647.0.html
Logged

Pages: [1]   Go Up
Jump to: