Hello again,
I am looking for a way to make something keep happening until a button is pressed. In particular, I want to loop lcd.blink until a number 1-9 is pressed on a 4x4 keypad. Or if someone could try to explain to me why my code is not printing a number after I press the * button, I would appreciate that as well. This is what I have so far:
#include <Keypad.h> //libraries
#include <Adafruit_LiquidCrystal.h>
static int count = 0; //variable used as first number
Adafruit_LiquidCrystal lcd_1(0);
const byte ROWS = 4;
const byte COLS = 4;
int del = 100;
int fabLoc = 11; // tells the location of the fabrication #
int partLoc = 7;// tells the location of the part #
int IR = 13;
int sensorStatus = digitalRead(IR);
void countUp(){
++count;
lcd_1.setCursor(7,1);
lcd_1.print(" ");
lcd_1.setCursor(7,1);
lcd_1.print(count);
}
void countDown(){
if(count!=0){
--count;
lcd_1.setCursor(7,1);
lcd_1.print(" ");
lcd_1.setCursor(7,1);
lcd_1.print(count);
}
}
char hexaKeys [ROWS][COLS] ={
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup()
{
Serial.begin(9600);
pinMode (IR, INPUT);
lcd_1.begin(16, 2);
lcd_1.print("Fab Cell #");
lcd_1.setCursor(0,1);
lcd_1.print("Part #");
lcd_1.setCursor(7,1);
lcd_1.print(count);
}
void loop(){
char customKey = customKeypad.getKey();
if (customKey=='C'){
countUp();
}
if (customKey=='D'){
countDown();
}
if (sensorStatus==1){
countUp();
}
switch (customKey){
case '*':
// This is where I believe my issue is
do{
lcd_1.setCursor(fabLoc,0);
lcd_1.print(" ");
lcd_1.setCursor(fabLoc,0);
lcd_1.blink();
}while (((customKey>='0') && (customKey <= '9')));
if ((customKey>='0') && (customKey <= '9')) {
lcd_1.setCursor(fabLoc,0);
lcd_1.noBlink();
delay(del);
lcd_1.print(customKey);
Serial.println(customKey);
}
break;
case'#':
lcd_1.setCursor(partLoc,1);
lcd_1.print(" ");
lcd_1.setCursor(partLoc,1);
lcd_1.blink();
if ((customKey>='0') && (customKey <= '9')) {
lcd_1.noBlink();
delay(del);
lcd_1.print(customKey);
Serial.println(customKey);
}
break;
}
}