Hello,
I've had my Uno for approx 2wks and am spending soo much time learning as much as I can. Youtube, Google, Blogs, Examples, PDF (terrible instructions from the kit), etc.
**Please not, I have no coding experience and and a total noob to the Arduino world. **
I have a piece I'm working on and I'm stuck in a strange loop or bug or code error. In fact, it's most def a code error (I have no idea what I'm doing). I've interpreted pieces of code from other projects (simulated on circuits.io).
Heres my code so far:
/* @file HelloKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates the simplest use of the matrix Keypad library.
|| #
*/
#include <Keypad.h>
#include <LiquidCrystal.h>
//initialize the library with the numbers of the interface pins
//LCD lcd(RS, E,D4,D5,d6,d7)
LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);
// 4x4 Matrix key pad
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
// define the key map
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
//connect to the row pinouts of the keypad
byte rowPins[ROWS] = {9, 8, 7, 6};
//connect to the column pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("C1 Pro Test");
lcd.setCursor(0,1);
//lcd.print("Press Any Key");
}
void loop(){
char key = keypad.getKey();
lcd.setCursor(0,1);
/*
while(key == NO_KEY) {
key = keypad.getKey();
}
*/
if (key){
Serial.println(key);
//lcd.println(" ");
//delay(10);
lcd.println("Capture ");
}
}
I can get the LCD to turn on and display my intro text
"C1 Pro Test"
and, when I press a key on the keypad, I see the corresponding keypad value on the serial monitor, although it seems inconsistent, and the word "Capture" does appear, but I can't get it to disappear without clearing the whole screen.
I've tried (you'll see the //comments above), to add "Press Any Key", in the intro text, but when I do, the "Capture" word won't register anymore. I don't understand.
I don't understand all of it actually, I've been copying and pasting code from other projects.
I tried using a while command to hold the loop to wait for a key press then clear the bottom line and display then an if to look for the key press, but that didn't work either.
Down the line, I'd like the keypad to behave like a logic keyboard and send keystrokes to my Mac.
Press A = send the CMD+K keystroke
Press 1 through 9 = keyboard # 1 to 9
I tried this:
void loop(){
char key = keypad.getKey();
lcd.setCursor(0,1);
if (key == "A"){
Serial.println(key);
lcd.println("Capture ");
}
}
But I get an error, "C++ forbids comparison between pointer and integer".
Need help.
Am I on the right track.
M.