Hi there, new to this Arduino stuff here, but certainly not to programming. I have experience with the basics of programming and logic design, C++, and a tad bit of Visual C++. I also have a general working knowledge of AC/DC electrical circuits.
Anyways, I'm here to upload my project idea of mine and I've already worked on some coding to implement the User Interface portion of it. It's a pet habitat controller and its going to be designed to measure temperature and humidity and adjust things according to the user's set parameters. The controller part of it, which i haven't coded yet will handle 2x things, switching on some sort of heating element and misting the pet habitat with water to raise the humidity levels. The habitat controller will implement a 16x2 LCD to display current readings and when the mode switch is flipped into the off position it will allow the user to adjust the desired readings so the controller will know when to make adjustments. I've basically have coded the 2x modes, auto cycle mode in which the controller will display current sensor values, and the programming mode in which the user can adjust temp and humidity. I've basically been only tweaking the user interface coding to remove any possible errors, like clearing the LCD of any hanging characters that were not overwritten by the last print command, and also prevented the user from adjusting any temp or humidity settings to go lower than 0. (I know temp can go below 0, but it's not like I have any pets that live in those conditions roflmao)
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 7, 6, 5, 4);
const int digitalPin1 = 9; //mode switch
const int digitalPin2 = 3; //button 1
const int digitalPin3 = 2; //button 2
const int digitalPin4 = 1; //button 3
int value1 = 0; //programming mode switch
int value2 = 0; //Up button
int value3 = 0; //Down button
int value4 = 0; //Enter button
int select = 0; //determines which value to adjust while programming
int temp = 85; //dummy sensor values
int humidity = 60; //dummy sensor value
void setup() {
lcd.begin(16, 2);
}
void loop() {
value1 = digitalRead(digitalPin1);
value2 = digitalRead(digitalPin2);
value3 = digitalRead(digitalPin3);
value4 = digitalRead(digitalPin4);
if(temp < 0) { //prevents adjusting temp into negative values
temp = 1;
}
if(humidity < 0) { //prevents adjusting humidity into negative values
humidity = 10;
}
if(value1 == 0) { //starts the programming mode
lcd.setCursor(0, 0);
lcd.print("Programming Mode");
lcd.setCursor(0, 1);
lcd.print(temp); //prints values
if(temp < 100) { //cleans screen of hanging digits from adjusting triple to double digit values
lcd.setCursor(3, 1);
lcd.print(" ");
}
lcd.setCursor(3, 1);
lcd.print((char)223);
lcd.setCursor(4, 1);
lcd.print("F");
lcd.setCursor(12, 1);
lcd.print(humidity);
if(humidity < 100) { //cleans screen of hanging digits from adjusting triple to double digit values
lcd.setCursor(14, 1);
lcd.print(" ");
}
lcd.setCursor(15, 1);
lcd.print("%");
if(value4 == 1) {
select = 1;
}
if(select > 0) {
lcd.setCursor(6, 1);
lcd.print(" ->"); //prints an arrow to show which value your currently editing and covers up the old one
if(value2 == 1) { //adjusts humidity up
humidity = (humidity + 10);
delay(500);
}
if(value3 == 1) { //adjusts humidity down
humidity = (humidity - 10);
delay(500);
}
}
if(select < 1) {
lcd.setCursor(6, 1);
lcd.print("<-"); //prints an arrow to show which value your currently editing
if(value2 == 1) { //adjusts temp up
temp = (temp + 1);
delay(500);
}
if(value3 == 1) { //adjusts temp down
temp = (temp - 1);
delay(500);
}
}
}
if(value1 == 1) { //enters auto cycle mode
select = 0;
lcd.setCursor(6, 1);
lcd.print(" "); //clears arrows from programming mode
lcd.setCursor(0, 0);
lcd.print("Auto-Cycle Mode");
lcd.setCursor(0, 1);
lcd.print(temp); //prints current readouts from sensors
lcd.setCursor(3, 1);
lcd.print((char)223);
lcd.setCursor(4, 1);
lcd.print("F");
lcd.setCursor(12, 1);
lcd.print(humidity);
lcd.setCursor(15, 1);
lcd.print("%");
}
}
Right now my brain is having a mental block with some of this coding as I currently stuck trying to code it were I can go back and forth between adjusting temp and humidity without having to flip the mode switch back and forth. It's quick and easy so there really isn't a need for it too much, but if anyone knows a simple method to doing so i'm open to any suggestions. I'm also open to any suggestions on how to shorten any of the coding if at all possible.