Hello,
i dont work with the arduino, we work in school with the texas instruments but the programming is the same. I think the arduino forum is more helpful than the energia forum.
I have a keypad 4x4 and want to control relays with my script. I wrote a script, but it doesn´t work.
Can anyone help me with my problem?
#include <Keypad.h>
const byte numRows= 4; //number of rows on the keypad
const byte numCols= 4; //number of columns on the keypad
//keymap defines the key pressed according to the row and columns just as appears on the keypad
char keymap[numRows][numCols]=
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
//Code that shows the the keypad connections to the arduino terminals
byte rowPins[numRows] = {PF_3,PB_3,PC_4,PC_5}; //Rows 0 to 3
byte colPins[numCols]= {PC_7,PD_6,PD_7,PF_4}; //Columns 0 to 3//initializes an instance of the Keypad class
Keypad ourKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);int REL = PA_7;
void setup()
{
pinMode(REL,OUTPUT);
Serial.begin(9600);
Serial.begin(9600);//sets baud rate for serial communication
}
char lastKey=0;
void loop()
{char keypressed = ourKeypad.getKey();
if (keypressed != NO_KEY);
{
Serial.print(keypressed);
}
//} These two line are your problem
//{
//char key = keypad.getKey(); // keypad was not declared anywhere, I assume it was meant to be this:char key = ourKeypad.getKey();
if (int(key) == 1) {
digitalWrite(REL, LOW);
delay(1000);
digitalWrite(REL, HIGH);
delay(1000);
}
}