Hello,
I'm trying to make a led switch for an aquarium. I'm using an arduino UNO and MCU friend 2.4" TFT Touch screen. The touch screen use ST7783 and i'm using for my project the following library :
-Adafruit_GFX
-UTFTGLUE
-SPI
-MCUFRIEND_kbv
-RTClib
-Wire
It's not my first project but i used to use URTouch library wich is unfortunately not working with my screen. Furthermore, it's my first project with a touch screen.
My goal is to drive a MOFSET with my arduino to switch on and off LED lights on my aquarium. MOFSET is to make it like sunset and moonset.
I'm having trouble with the touch part. I use it to program the rise up hour and the differents paramterers. I would like to detect if i touch this area to change the parameters.
A second little problem is that i'm not able to whrite hour with 2 digits .... If Someone can help me it would be nice. Here is my actual code inspired by exemples on MCUFRIEND Library :
#include <Adafruit_GFX.h>
#include <UTFTGLUE.h>
#include <SPI.h>
#include <MCUFRIEND_kbv.h>
#include <RTClib.h>
#include <Wire.h>
#include <avr/pgmspace.h>
MCUFRIEND_kbv tft;
RTC_DS1307 rtc;
#include <TouchScreen.h>
#define YP A1
#define YM 7
#define XM A2
#define XP 6
UTFTGLUE myGLCD(0x7781, A2, A1, A3, A4, A0);
extern uint8_t BigFont[];
extern uint8_t Grotesk16x32[];
extern uint8_t SixteenSegment16x24[];
extern uint8_t SmallFont[];
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
uint32_t cx, cy;
uint32_t rx[8], ry[8];
int32_t clx, crx, cty, cby;
float px, py;
int dispx, dispy, text_y_center, swapxy;
uint32_t calx, caly, cals;
char buf[13];
#define TOUCH_ORIENTATION LANDSCAPE
TouchScreen myTouch(XP, YP, XM, YM, 300);
TSPoint tp;
void readResistiveTouch(void)
{
tp = myTouch.getPoint();
pinMode(YP, OUTPUT);
pinMode(XM, OUTPUT);
digitalWrite(YP, HIGH);
digitalWrite(XM, HIGH);
}
bool ISPRESSED(void)
{
int count = 0;
bool state, oldstate;
while (count < 10) {
readResistiveTouch();
state = tp.z > 20 && tp.z < 1000;
if (state == oldstate) count++;
else count = 0;
oldstate = state;
delay(5);
}
return oldstate;
}
void drawBoutons(int x, int y)
{
myGLCD.setColor(0,255,0);
myGLCD.drawRect(x,y+20,x+40,y-23);
myGLCD.drawRect(x+60,y+20,x+100,y-23);
myGLCD.drawLine(x+10,y-2,x+30,y-2);
myGLCD.drawLine(x+70,y-2,x+90,y-2);
myGLCD.drawLine(x+20,y+7,x+20,y-10);
}
void startup()
{
myGLCD.fillScr(0,0,0);
drawBoutons(200,33);
drawBoutons(200,83);
drawBoutons(200,133);
drawBoutons(200,183);
}
void get_heure(int h, int m, int s){
DateTime now= rtc.now();
m=int(now.minute());
h=int(now.hour());
s=int(now.second());
myGLCD.printNumI(h, 140, 230, 2, '0');
myGLCD.print(":", 155, 230);
myGLCD.printNumI(m, 170, 230, 2, '0');
}
void temps_parametres(){
long lsh,lsm,csh,csm,llh,llm,clh,clm;
lsh=17;
lsm=0;
csh=22;
csm=0;
llh=0;
llm=0;
clh=2;
clm=30;
myGLCD.printNumI(lsh,140,30, 2, '0');
myGLCD.printNumI(lsm,170,30, 2, '0');
myGLCD.printNumI(csh,140,80, 2, '0');
myGLCD.printNumI(csm,170,80, 2, '0');
myGLCD.printNumI(llh,140,130, 2, '0');
myGLCD.printNumI(llm,170,130, 2, '0');
myGLCD.printNumI(clh,140,180, 2, '0');
myGLCD.printNumI(clm,170,180, 2, '0');
}
void setup() {
digitalWrite(A0, HIGH);
pinMode(A0, OUTPUT);
myGLCD.InitLCD(TOUCH_ORIENTATION);
myGLCD.clrScr();
dispx = myGLCD.getDisplayXSize();
dispy = myGLCD.getDisplayYSize();
startup();
myGLCD.setColor(255,255,255);
myGLCD.setFont(Grotesk16x32);
myGLCD.print("Leve Soleil : ",20,30);
myGLCD.print(":", 155,30);
myGLCD.print("Couche Soleil : ",20,80);
myGLCD.print(":", 155,80);
myGLCD.print("Leve Lune : ",20,130);
myGLCD.print(":",155,130);
myGLCD.print("Couche Lune : ", 20,180);
myGLCD.print(":", 155,180);
myGLCD.setColor(255,0,255);
rtc.begin();
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
void loop() {
while (true) {}
}