/**
Arduino Uno Controller
Copyright (C) 2023, Tharana Madhawa.
*/
#include <LiquidCrystal.h>
#include <Keypad.h>
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
/* Display */
LiquidCrystal lcd(13, 12, 11, 9, 8, 7);
/* Keypad setup */
const byte KEYPAD_ROWS = 4;
const byte KEYPAD_COLS = 3;
byte rowPins[KEYPAD_ROWS] = {5, 4, 3, 2};
byte colPins[KEYPAD_COLS] = {A3, A2, A1};
char keys[KEYPAD_ROWS][KEYPAD_COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'C', '0', 'S'}
};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, KEYPAD_ROWS, KEYPAD_COLS);
void showSpalshScreen() {
lcd.print("Welcome to test");
lcd.setCursor(3, 1);
String message = "Controller";
for (byte i = 0; i < message.length(); i++) {
lcd.print(message[i]);
delay(50);
}
delay(2000);
}
void updateCursor() {
if (millis() / 250 % 2 == 0 ) {
lcd.cursor();
} else {
lcd.noCursor();
}
}
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
showSpalshScreen();
lcd.clear();
lcd.cursor();
lcd.setCursor(0, 0);
pinMode (10,OUTPUT);
}
String current = "";
int led1=10;
void processInput(char key) {
if (key != 'S' && key != 'C'){
lcd.print(key);
if (current == "") {
current = String(key);
} else {
current += String(key);
}
} else if (key == 'C') {
current = "";
lcd.clear();
lcd.cursor();
lcd.setCursor(0, 0);
} else {
int limit = current.toInt();
if (heatDetector() < 30) {
execute (limit);
} else {
Serial.print("Too hot!");
//exit(0);
}
}
}
void loop() {
updateCursor();
char key = keypad.getKey();
if (key != NO_KEY) {
//if (heatDetector < 30) {
processInput(key);
//} else {
// exit(0);
//}
}
}
void execute (int limit) {
for (int i=0; i<limit; i=i+1){
digitalWrite (led1,HIGH);
delay(100);
digitalWrite (led1,LOW);
delay(1000);
}
}
float heatDetector () {
int analogValue = analogRead(A0);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
Serial.print("Temperature: ");
Serial.print(celsius);
Serial.println(" ℃");
// delay(1000);
return celsius;
}