Hello all,
I am the proud owner of an 8-button pin pad, as seen in the link below:
http://dx.com/p/8-push-buttons-keypad-module-blue-150367?item=10
In my code, I commented out all the other buttons other than 0 and 1 for my sanity for the time being. The first time I tried this I had the G pin wired to GND and K0-K7 wired to a digital pin on my Mega 2560. That was giving me random results all the time so I tried something someone in another thread suggested:
http://arduino.cc/forum/index.php/topic,42198.0.html
I had the same problem as him, so I figured it must work. I figure now that the G pin on the keypad must be connected to a voltage source, so I plugged it into 5V. Still constantly on. Back to GND. Still constantly on. I am at wits end. I'm hoping someone else will see something I'm not?
Here is my code:
//Define keypad pins:
const int BUTTON0= 53; //input pin for button 0 on keypad
//button 0: Chandelier
int valBUT0=0;
const int BUTTON1= 52; //input pin for button 1 on keypad
//button 1: Desk Lamp
int valBUT1=0;
/*
const int BUTTON2= 23; //input pin for button 2 on keypad
//button 2: Speakers
int valBUT2=0;
const int BUTTON3= 24; //input pin for button 3 on keypad
//button 3: SELECT
int valBUT3=0;
const int BUTTON4= 25; //input pin for button 4 on keypad
//button 4: Blinds
int valBUT4=0;
const int BUTTON5= 26; //input pin for button 5 on keypad
//button 5: Floor Lamp
int valBUT5=0;
const int BUTTON6= 27; //input pin for button 6 on keypad
//button 6: Emery Lamp
int valBUT6=0;
const int BUTTON7= 28; //input pin for button 7 on keypad
//button 7: MENU
int valBUT7=0;
*/
//---------------------------------------------------------------------
void setup()
{
//Setup for keypad:
pinMode(BUTTON0, INPUT); //BUTTON0 is an input (on pin 53)
digitalWrite(BUTTON0, HIGH); //connects internal pullup resistor //write HIGH to input pin
pinMode(BUTTON1, INPUT); //BUTTON1 is an input (on pin 52)
digitalWrite(BUTTON0, HIGH);
/*
pinMode(BUTTON2, INPUT); //BUTTON2 is an input (on pin 23)
pinMode(BUTTON3, INPUT); //BUTTON3 is an input (on pin 24)
pinMode(BUTTON4, INPUT); //BUTTON4 is an input (on pin 25)
pinMode(BUTTON5, INPUT); //BUTTON5 is an input (on pin 26)
pinMode(BUTTON6, INPUT); //BUTTON6 is an input (on pin 27)
pinMode(BUTTON7, INPUT); //BUTTON7 is an input (on pin 28)
*/
// open the serial port at 9600 bps:
Serial.begin(9600);
}
//----------------------------------------------------------------------------
void loop()
{
//Check for input from Keypad:
valBUT0= digitalRead(BUTTON0); //read input from Button 0 and store it
//Button0: Chandelier
valBUT1= digitalRead(BUTTON1); //read input from Button 1 and store it
//Button1: Desk Lamp
/*
valBUT2= digitalRead(BUTTON2); //read input from Button 2 and store it
//Button2: Speaker
valBUT3= digitalRead(BUTTON3); //read input from Button 3 and store it
//Button3: SELECT
valBUT4= digitalRead(BUTTON4); //read input from Button 4 and store it
//Button4: Blinds
valBUT5= digitalRead(BUTTON5); //read input from Button 5 and store it
//Button5: Floor Lamp
valBUT6= digitalRead(BUTTON6); //read input from Button 6 and store it
//Button6: Emery Lamp
valBUT7= digitalRead(BUTTON7); //read input from Button 7 and store it
//Button7: MENU
*/
//check whether in input is HIGH (button pressed):
if(digitalRead(BUTTON0 == LOW))
{
//switch is closed
Serial.println("Chandelier");
Serial.println(" ");
delay(300);
}
else
{
//switch is open
//do nothing
}
if(digitalRead(BUTTON1==LOW))
{
//switch is closed
Serial.println("Desk Lamp");
Serial.println(" ");
delay(300);
}
else
{
//switch is open
//do nothing
}
/*
if(valBUT2==HIGH)
{
Serial.println("Speaker");
Serial.println(" ");
delay(300);
}
else
{
//do nothing
}
if(valBUT3==HIGH)
{
Serial.println("SELECT");
Serial.println(" ");
delay(300);
}
else
{
//do nothing
}
if(valBUT4==HIGH)
{
Serial.println("Blinds");
Serial.println(" ");
delay(300);
}
else
{
//do nothing
}
if(valBUT5==HIGH)
{
Serial.println("Floor Lamp");
Serial.println(" ");
delay(300);
}
else
{
//do nothing
}
if(valBUT6==HIGH)
{
Serial.println("Emery Lamp");
Serial.println(" ");
delay(300);
}
else
{
//do nothing
}
if(valBUT7==HIGH)
{
Serial.println("MENU");
Serial.println(" ");
delay(300);
}
*/
} //END OF PROGRAM
I am getting so much rando