Hi,
I’ve been working on the following code for several weeks now as a first project.
Everything is working out slowely, but when i added a new peice of code to the void loop to add temperature probe then the touch screen buttons no longer work .
Im guessing for some reason its not going back to the top of the loop, :S…
im a newbie at this so the code below im sure is not tidy or well written.
Any changes or help would be appreciated.
#include <UTFT.h>
#include <UTouch.h>
#include <DS1307.h>
#include <Servo.h>
/*************************
** New Code for Temp **
*************************/
#include <OneWire.h>
#define RELAY_PIN 3
#define RELAY_PIN1 6
#define ledPin2 5
#define ledPin3 4
// Init the DS1307
DS1307 rtc(20, 21);
OneWire ds(10); // on pin 10 (a 4.7K resistor is necessary)
// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
UTFT myGLCD(ITDB32S, 38,39,40,41); // Remember to change the model parameter to suit your display module!
UTouch myTouch(6,5,4,3,2);
int x, y;
char stCurrent[20]="";
int stCurrentLen=0;
char stLast[20]="";
int ledPin = 13;
int relayPin1 = 8; // for SKIMMER
int relayPin2 = 9; // for PUMP
int relayPin3 = 11; // for EXT FILTER
int reset = 30; // reset Button
int ledPin1 = 2; // LED Blue for Cold
//int ledPin2 = 5; // LED RED for HOT
//int ledPin3 = 4; // LED Green for Normal
int fanPin1 = A1; //Fan pin
long num;
char num1;
float tempW = 0;
/*************************
** Custom functions **
*************************/
void drawButtons()
{
// Draw the buttons
// Setting title with blue colour and big text
myGLCD.setBackColor(0x0000);
myGLCD.setFont(SmallFont);
myGLCD.setColor(0xC618);
myGLCD.print("Aquarium Information", 60, 0);
//draw button 1 TIME
myGLCD.setColor(0x0000);
myGLCD.fillRoundRect (1, 15, 155, 65);
myGLCD.setColor(0xC618);
myGLCD.drawRoundRect (1, 15, 155, 65);
myGLCD.setBackColor(0x0000);
myGLCD.setFont(SmallFont);
myGLCD.setColor(0xFD20);
myGLCD.print("TIME:", 10, 20);
//draw button 2 DATE
myGLCD.setColor(0x0000);
myGLCD.fillRoundRect (160, 15, 310, 65);
myGLCD.setColor(0xC618);
myGLCD.drawRoundRect (160, 15, 310, 65);
myGLCD.setBackColor(0x0000);
myGLCD.setFont(SmallFont);
myGLCD.setColor(0xFD20);
myGLCD.print("DATE:", 170, 20);
//draw button 3 Water Temperature
myGLCD.setColor(0x0000);
myGLCD.fillRoundRect (1, 70, 155, 125);
myGLCD.setColor(0xC618);
myGLCD.drawRoundRect (1, 70, 155, 125);
myGLCD.setBackColor(0x0000);
myGLCD.setFont(SmallFont);
myGLCD.setColor(0xFD20);
myGLCD.print("Water Temperature:", 10, 75);
//draw button 4 Feed Fish
myGLCD.setColor(0x0000);
myGLCD.fillRoundRect (160, 70, 310, 125);
myGLCD.setColor(0xC618);
myGLCD.drawRoundRect (160, 70, 310, 125);
myGLCD.setBackColor(0x0000);
myGLCD.setFont(SmallFont);
myGLCD.setColor(0xFD20);
myGLCD.print("Feed Fish:", 170, 85);
//draw button 5 PH
myGLCD.setColor(0x0000);
myGLCD.fillRoundRect (1, 130, 155, 175);
myGLCD.setColor(0xC618);
myGLCD.drawRoundRect (1, 130, 155, 175);
myGLCD.setBackColor(0x0000);
myGLCD.setFont(SmallFont);
myGLCD.setColor(0xFD20);
myGLCD.print("PH LVL:", 10, 140);
//draw button 6 Reset Button
myGLCD.setColor(0x0000);
myGLCD.fillRoundRect (160, 130, 310, 175);
myGLCD.setColor(0xC618);
myGLCD.drawRoundRect (160, 130, 310, 175);
myGLCD.setBackColor(0x0000);
myGLCD.setFont(SmallFont);
myGLCD.setColor(0xF800);
myGLCD.print("RESET", 170, 140);
//draw button 7 SKIMMER
myGLCD.setFont(SmallFont);
myGLCD.setColor(0x0000);
myGLCD.fillRoundRect (1, 180, 100, 230);
myGLCD.setColor(0x07FF);
myGLCD.drawRoundRect (1, 180, 100, 230);
myGLCD.setBackColor(0x0000);
myGLCD.print("SKIMMER", 20, 190);
myGLCD.setFont(BigFont);
myGLCD.setColor(0x07FF);
myGLCD.print("ON", 10, 210);
myGLCD.setColor(0x07E0);
myGLCD.setColor(0x07FF);
myGLCD.print("OFF", 50, 210);
//draw button 8 PUMP
myGLCD.setFont(SmallFont);
myGLCD.setColor(0x0000);
myGLCD.fillRoundRect (105, 180, 200, 230);
myGLCD.setColor(0x07FF);
myGLCD.drawRoundRect (105, 180, 200, 230);
myGLCD.print("PUMP", 135, 190);
myGLCD.setFont(BigFont);
myGLCD.setColor(0x07FF);
myGLCD.print("ON", 110, 210);
myGLCD.setColor(0x07FF);
myGLCD.print("OFF", 150, 210);
//draw button 8 External Filter
myGLCD.setFont(SmallFont);
myGLCD.setColor(0x0000);
myGLCD.fillRoundRect (205, 180, 310, 230);
myGLCD.setColor(0x07FF);
myGLCD.drawRoundRect (205, 180, 310, 230);
myGLCD.print("EXT FILTER", 215, 190);
myGLCD.setFont(BigFont);
myGLCD.setColor(0x07FF);
myGLCD.print("ON", 210, 210);
myGLCD.setColor(0x07FF);
myGLCD.print("OFF", 260, 210);
}
void updateStr(int val)
{
if (stCurrentLen<20)
{
stCurrent[stCurrentLen]=val;
stCurrent[stCurrentLen+1]='\0';
stCurrentLen++;
myGLCD.setColor(0, 255, 0);
myGLCD.print(stCurrent, LEFT, 224);
}
else
{
myGLCD.setColor(255, 0, 0);
myGLCD.print("BUFFER FULL!", CENTER, 192);
delay(500);
myGLCD.print(" ", CENTER, 192);
delay(500);
myGLCD.print("BUFFER FULL!", CENTER, 192);
delay(500);
myGLCD.print(" ", CENTER, 192);
myGLCD.setColor(0, 255, 0);
}
}
/*************************
** Required functions **
*************************/
void setup()
{
// Set the clock to run-mode
rtc.halt(false);
// Setup Serial connection
Serial.begin(9600);
rtc.setDOW(SUNDAY); // Set Day-of-Week to SUNDAY
rtc.setTime(17, 13, 0); // Set the time to 12:00:00 (24hr format)
rtc.setDate(6, 7, 2013); // Set the date to October 3th, 2010
// Initial setup
myGLCD.InitLCD();
myGLCD.clrScr();
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
myGLCD.setFont(BigFont);
myGLCD.setBackColor(0, 0, 255);
drawButtons();
//set pin as output
pinMode(ledPin, OUTPUT);
//set relaypin as output
pinMode(relayPin1, OUTPUT);
pinMode(relayPin2, OUTPUT);
pinMode(relayPin3, OUTPUT);
// pinMode(reset, OUTPUT);
pinMode(RELAY_PIN, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
}
}