Hey guys, I'm going to be as clear as possible with this, but if there is more information needed, please just ask.
I'm using an Arduino UNO for a university project, and the only roadblock that I seem to be running into is that I can't seem to program the keypad to select between a few cases.
If the problem is due to not connecting the whole keypad, my question becomes: Is there a way to use only certain parts of the keypad (in my case I only want to use 1 and 2)
There are no errors when this code is run.
I'm not sure what is wrong, I'm not very experienced in programming so most of this code is re purposed from what I found on the internet. I can provide links (usually other forum posts).
I'm using the 4x4 keypad with the ABCD on the side. (no clue the part #)
I'm expecting this code to react to me pushing 1 or 2 and then run one of the two for loops (and then allow another selection if necessary).
Memory usage:
Sketch uses 5326 bytes (16%) of program storage space. Maximum is 32256 bytes.
Global variables use 230 bytes (11%) of dynamic memory, leaving 1818 bytes for local variables. Maximum is 2048 bytes.
I'm cutting this off partway through due to the code afterwards being functional.
#include <LiquidCrystal.h>
#include <Keypad.h>
LiquidCrystal lcd(4, 1, 8, 7, 6, 5);
const byte ROWS = 1;
const byte COLS = 2;
char Keys[ROWS][COLS] = {
{'1', '2'}
};
byte rowPins[ROWS] = {13};
byte colPins[COLS] = {12, 3};
Keypad myKeypad= Keypad(makeKeymap(Keys), rowPins, colPins, ROWS, COLS);
enum state {hot, cold, neither} current_state = neither;
int buttonState = 0;
int lastButtonState = 0;
int buttonPushCounter = 0;
int buttonState2 = 0;
int lastButtonState2 = 0;
int buttonPushCounter2 = 0;
int sensorPin=0;
//analog pin 0 for temp
void setup()
{
pinMode(2, INPUT);
pinMode(9, INPUT);
lcd.begin(16, 2);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
}
void loop()
{
char preSet=myKeypad.getKey();
switch (current_state){
case hot:
for (int i=0; i <=25; i++){
digitalWrite(10,HIGH);
delay(1000);
digitalWrite(10, LOW);
delay(1000);
}
break;
case cold:
digitalWrite(11, HIGH);
delay(1000);
digitalWrite(11, LOW);
break;
case neither:
break;
}
switch (myKeypad.getState()){
case PRESSED:
switch(preSet){
case '1': current_state = hot;
case '2': current_state = cold;
case 'NO_KEY': current_state = neither;
}
break;
}