Thanks liudr. I'm so sorry, my code above is too messy.
I want to built a circuit that will monitor a certain temperature of a system.
It allows me to enter the set point/reference temperature and temperature guardband.
I'm using a 16x2 LCD and 4x3 keypad.
I will pin 13 as an output that will LED is off when out-of-temperature.
I used potentiometer instead of temperature sensor for playing purposes.
Now, still trying to write a code that will look like this.
Can somebody help me to figure out what correct code to be used.
And Iwant to store the value, so that I can able to do math functions for LED output.
when setting the setpoint and guardband temperature:
//Default display
Temperature
30°C
//Display when pressing *
//cursor blinks at (11,0)
Setpoint : _
Guardband :
//print a key then # as an enter
//cursor blinks at (11,1)
Setpoint : 25
Guardband : _
//print a key then # as an enter
//hold for 3 seconds
Setpoint : 25
Guardband : 3
//after 3 second will back to default display
Temperature
30°C
When displaying the setpoint and guardband temperature:
//Default display
Temperature
30°C
//Display when pressing #
//hold for 3 seconds
Setpoint : 25°C
Guardband : +/- 3
//after 3 second will back to default display
Temperature
30°C
/*
comment here
*/
#include <Keypad.h> // include the Keypad code:
#include <LiquidCrystal.h> // include the library code:
const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
char keys[ROWS][COLS] = { // Define the Keymap
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = { 12, 11, 10, 9 }; // Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte colPins[COLS] = { 8, 7, 6 }; // Connect keypad COL0, COL1 and COL2 to these Arduino pins.
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); // Create the Keypad
LiquidCrystal lcd(5, 4, 3, 2, 1, 0); // initialize the library with the numbers of the interface pins
int analogPin = 5; // potentiometer wiper (middle terminal) connected to analog pin 3, outside leads to ground and +5V
int val = 0; // variable to store the value read
uint8_t DegreeBitmap[]= { 0x6, 0x9, 0x9, 0x6, 0x0, 0, 0, 0 }; // create a dot character pattern for degree symbol
void setup()
{
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
lcd.createChar ( 1, DegreeBitmap ); // install the custom degree symbol as character #1
}
void loop()
{
char key = keypad.getKey();
if(key) // same as if(key != NO_KEY)
{
switch (key)
{
case '*':
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Setpoint: ");
lcd.setCursor(12, 0);
lcd.cursor();
delay(500);
lcd.print(key);
lcd.setCursor(0, 1);
lcd.print("Guardband: ");
lcd.setCursor(12, 1);
lcd.print(key);
break;
case '#':
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Cancel");
break;
}
}
}