Part 2:
void displaytemps()
{
lcd.writeString(75, 0, "C", MENU_NORMAL);
lcd.writeString(75, 1, "C", MENU_NORMAL);
lcd.writeString(75, 2, "C", MENU_NORMAL);
lcd.writeString(75, 3, "C", MENU_NORMAL);
lcd.writeString(75, 4, "C", MENU_NORMAL);
readsensors();
itoa(temp1, temp, 10);
lcd.writeString(60, 0, temp, MENU_NORMAL);
itoa(temp2, temp, 10);
lcd.writeString(60, 1, temp, MENU_NORMAL);
itoa(temp3, temp, 10);
lcd.writeString(60, 2, temp, MENU_NORMAL);
itoa(temp4, temp, 10);
lcd.writeString(60, 3, temp, MENU_NORMAL);
itoa(temp5, temp, 10);
lcd.writeString(60, 4, temp, MENU_NORMAL);
}
// Display temperature in big digits, humidity in small digits underneath
void temperature() {
long lastUpdate = 0; // Force update
byte i;
byte key = 0xFF;
// Display non changing text, there is a slight delay while first reading is taken
lcd.writeString(0, 0, "Number", MENU_NORMAL);
lcd.writeString(10, 1, "Of", MENU_NORMAL);
lcd.writeString(0, 2, "Showers", MENU_NORMAL);
lcd.writeString(0, 3, "avail:", MENU_NORMAL);
lcd.writeString(38, 5, "OK", MENU_HIGHLIGHT );
// Loop to display temperaure/humidity with check for key press to exit
while (key!= CENTER_KEY) {
// Update temp
if( millis() > lastUpdate + 1000) {
// Read temperature and humidity
displaytemps();
lcd.writeString(5, 4, shower, MENU_NORMAL);
lastUpdate = millis();
}
key = checkKeypressed();
}
}
void waterreq() {
current_menu_num = 1;
current_menu_item = 0;
}
void mainmenu() {
current_menu_num = 0;
current_menu_item = 0;
}
void shower1()
{
char* newtemp;
char* oldtemp;
readsensors();
oldtemp = shower;
while (oldtemp < "1")
{
//delay(1000);
displaytemps();
digitalWrite(3, HIGH);
lcd.writeString(10, 2, "HEATING", MENU_NORMAL);
newtemp = shower;
oldtemp = newtemp;
}
current_menu_num = 0;
current_menu_item = 0;
}
void shower15()
{
char* newtemp;
char* oldtemp;
readsensors();
oldtemp = shower;
while (oldtemp < "1.5")
{
//delay(1000);
displaytemps();
lcd.writeString(10, 2, "HEATING", MENU_NORMAL);
newtemp = shower;
oldtemp = newtemp;
}
current_menu_num = 0;
current_menu_item = 0;
};
void shower2()
{
char* newtemp;
char* oldtemp;
readsensors();
oldtemp = shower;
while (oldtemp < "2")
{
//delay(1000);
displaytemps();
lcd.writeString(10, 2, "HEATING", MENU_NORMAL);
newtemp = shower;
oldtemp = newtemp;
}
current_menu_num = 0;
current_menu_item = 0;
};
void shower25()
{
char* newtemp;
char* oldtemp;
readsensors();
oldtemp = shower;
while (oldtemp < "2.5")
{
displaytemps();
lcd.writeString(10, 2, "HEATING", MENU_NORMAL);
newtemp = shower;
oldtemp = newtemp;
}
current_menu_num = 0;
current_menu_item = 0;
};
void bath()
{
char* newtemp;
char* oldtemp;
readsensors();
oldtemp = shower;
while (oldtemp < "Bath")
{
//delay(1000);
displaytemps();
lcd.writeString(10, 2, "HEATING", MENU_NORMAL);
newtemp = shower;
oldtemp = newtemp;
}
current_menu_num = 0;
current_menu_item = 0;
};
void none()
{
current_menu_num = 0;
current_menu_item = 0;
};
// The followinging are interrupt-driven keypad reading functions
// which includes DEBOUNCE ON/OFF mechanism, and continuous pressing detection
// Convert ADC value to key number
char get_key(unsigned int input) {
char k;
for (k = 0; k < NUM_KEYS; k++) {
if (input < adc_key_val[k]) {
return k;
}
}
if (k >= NUM_KEYS)
k = -1; // No valid key pressed
return k;
}
void update_adc_key() {
int adc_key_in;
char key_in;
byte i;
adc_key_in = analogRead(0);
key_in = get_key(adc_key_in);
for(i=0; i<NUM_KEYS; i++) {
if(key_in==i) { //one key is pressed
if(button_count[i]<DEBOUNCE_MAX) {
button_count[i]++;
if(button_count[i]>DEBOUNCE_ON) {
if(button_status[i] == 0) {
button_flag[i] = 1;
button_status[i] = 1; //button debounced to 'pressed' status
}
}
}
} else { // no button pressed
if (button_count[i] >0) {
button_flag[i] = 0;
button_count[i]--;
if(button_count[i]<DEBOUNCE_OFF) {
button_status[i]=0; //button debounced to 'released' status
}
}
}
}
}
// Timer2 interrupt routine -
// 1/(160000000/256/(256-6)) = 4ms interval
ISR(TIMER2_OVF_vect) {
TCNT2 = 6;
update_adc_key();
}