Code:
// ChipKIT UNO 32 12-port Temperature Center Shield
// Code Written by Crenn (www.thebestcasescenario.com)
// Designed by Will Lyon (www.computersandcircuits.com)
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see http://www.gnu.org/licenses/
// Libraries
#include <LiquidCrystal.h>
// Global Constants
const unsigned short START_MES_DIS_TIME=3;
const unsigned short ACTION_TIME=5;
const unsigned short UPDATE_TIME=1;
const unsigned short MILLIS_IN_SEC=1000;
const unsigned short SMDT_IN_MS=START_MES_DIS_TIME*MILLIS_IN_SEC;
const unsigned short AT_IN_MS=ACTION_TIME*MILLIS_IN_SEC;
const unsigned short UT_IN_MS=UPDATE_TIME*MILLIS_IN_SEC;
const byte TEMP_PINS=12;
const byte NO_TEMPS_ON_LCD=2;
const byte TEMP_SETS=TEMP_PINS/NO_TEMPS_ON_LCD;
const byte TEMP_PIN_MAP[NO_TEMPS_ON_LCD][TEMP_SETS]={
{14,16,18,20,22,24} , {15,17,19,21,23,25}
};
const byte LCD_COLS=16;
const byte LCD_ROWS=2;
// The +1 is to allow for the null character at the end of the string
const char WELCOME_LA[LCD_COLS+1]=" "; // edit these to change the opening message display. Line 1 on top, line 2 on bottom
const char WELCOME_LB[LCD_COLS+1]=" ";
const char TEMP_L[]="TEMP ";
const byte TEMP_CUST_CHARS=7;
const byte TEMP_CUSTOM[TEMP_PINS][TEMP_CUST_CHARS+1]={
{"TEMP 1"},{"TEMP 2"},{"TEMP 3"},{"TEMP 4"}, // Change these to edit the temp zone display names. Max 8 characters each!
{"TEMP 5"},{"TEMP 6"},{"TEMP 7"},{"TEMP 8"}, // You will need to adjust the spacing and upload to get it where you want it
{"TEMP 9"},{"TEMP 10"},{"TEMP 11"},{"TEMP 12"}
};
const char TEMP_S[]={0xDF,'C'};
// Global Variables
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
byte temp_pin_pointer=0;
unsigned short temp_values[NO_TEMPS_ON_LCD][TEMP_SETS];
byte temp_lcda=1;
byte temp_lcdb=2;
byte welc_disp=0;
unsigned long tsla; // time_since_last_action;
unsigned long tslu; // time_since_last_update;
double convertTemp(unsigned short ttbc) {
if (ttbc > 237 && ttbc < 748) {
return (ttbc-237)*0.0939947781;
}
return 0.0;
}
// Temperature Sensor Functions
void newTemps() {
temp_lcda=(TEMP_PIN_MAP[0][temp_pin_pointer]-13);
temp_lcdb=(TEMP_PIN_MAP[1][temp_pin_pointer]-13);
}
void updateTemps() {
for(byte i=0;i<TEMP_SETS;i++) {
temp_values[0][i]=analogRead(TEMP_PIN_MAP[0][i]);
temp_values[1][i]=analogRead(TEMP_PIN_MAP[1][i]);
}
}
void displayTemps() {
unsigned char spaces = 2;
double temp_conv = 0.0;
lcd.setCursor(0, 0);
if(TEMP_CUSTOM[(temp_lcda-1)][0] != 0) {
for (int i=0;i<TEMP_CUST_CHARS;i++) {
if(TEMP_CUSTOM[(temp_lcda-1)][i] != 0) {
lcd.print(TEMP_CUSTOM[(temp_lcda-1)][i]);
}
else {
spaces = 8-i;
break;
}
}
}
else {
lcd.print(TEMP_L);
if(temp_lcda < 10) {
lcd.print(' ');
}
lcd.print(temp_lcda,DEC);
spaces = 2;
}
for (int i=0;i<spaces;i++) {
lcd.print(' ');
}
if(TEMP_CUSTOM[(temp_lcdb-1)][0] != 0) {
for (int i=0;i<TEMP_CUST_CHARS;i++) {
if(TEMP_CUSTOM[(temp_lcdb-1)][i] != 0) {
lcd.print(TEMP_CUSTOM[(temp_lcdb-1)][i]);
}
else {
spaces = 8-i;
break;
}
}
}
else {
lcd.print(TEMP_L);
if(temp_lcdb < 10) {
lcd.print(' ');
}
lcd.print(temp_lcdb,DEC);
spaces = 0;
}
if (spaces != 0) {
for (int i=0;i<spaces;i++) {
lcd.print(' ');
}
}
spaces = 3;
lcd.setCursor(0, 1);
temp_conv=convertTemp(temp_values[0][temp_pin_pointer]);
if (temp_conv<10) {
lcd.print(' ');
}
lcd.print(temp_conv,1);
lcd.print(TEMP_S);
for (int i=0;i<spaces;i++) {
lcd.print(' ');
}
temp_conv=convertTemp(temp_values[1][temp_pin_pointer]);
if (temp_conv<10) {
lcd.print(' ');
}
lcd.print(temp_conv,1);
lcd.print(TEMP_S);
}
void displayWel() {
lcd.setCursor(0, 0);
lcd.print(WELCOME_LA);
lcd.setCursor(0, 1);
lcd.print(WELCOME_LB);
}
void setup() {
lcd.begin(LCD_COLS, LCD_ROWS);
displayWel();
tsla = millis();
while (millis() < (tsla + SMDT_IN_MS));
tsla = millis();
updateTemps();
displayTemps();
}
void loop() {
if (millis() > (tsla + AT_IN_MS)) {
if (welc_disp == 1) {
temp_pin_pointer = 0;
welc_disp = 0;
updateTemps();
}
else {
++temp_pin_pointer;
}
if (temp_pin_pointer >= TEMP_SETS) {
displayWel();
welc_disp = 1;
}
else {
newTemps();
displayTemps();
}
tsla = millis();
}
if (temp_pin_pointer < TEMP_SETS) {
if (millis() > (tslu + UT_IN_MS)) {
updateTemps();
displayTemps();
tslu = millis();
}
}
}