Mega2560 + 3.2 TFT Touch, automated terrarium control + manual buttons
hi,
i started arduino programming few days ago, because coworker asked me if wanted use control terrariums in convenient way. well, said yes , don't regret far. until used raspberrypi , cronjob switch lights, didn't work well.
but seems stuck, hope of willing give me advice.
my setup:
- set: http://www.sainsmart.com/sainsmart-mega2560-board-3-5-tft-lcd-module-display-shield-kit-for-atmel-atmega-avr-16au-atmega8u2.html (arduino mega2560 + 3.2 tft touch screen + shield)
- ds1307 timer (sda -> analog 0, sdc -> analog 2)
- 433mhz transmitter control remote sockets (the remote sockets elro ab440s, transmitter 1 of billions of transmitters can buy 1€/$) (data -> pin
what trying do?
- automatically switch lights in terrariums on/off, while simulating different seasons (no light during winter, longest during summer, etc.) -> main reason why don't want use standard time switches, since ususally not allow many different times depending on date
- print buttons on touch screen can manually switch additional remote sockets (e.g. tv, pc, lights, ...)
right now, buttons used in case goes wrong. got 1 button switches in terrariums on, 1 switches off , 1 doesn't far.
my problem:
- timer works fine. lights switched on/off want them to.
- can't use buttons. in examples buttons implemented using infinite while loop, can't use because timer wouldn't work if did. if-functions switch lights not included in while loop controls buttons, if while loop infinite, if-functions never reached.
i guess 1 of problems don't draw buttons during execution of "void loop" function. if that, drawn continously, resulting in flickering buttons. if add "draw buttons" part "void loop"function, doesn't work. can press button, shows red frame around button while pressed, doesn't execute commands.
i included code (with part of timer cut out keep short). important part right @ beginning of void loop function, tried make buttons work.
p.s, - in advance:
1. sorry long post, wanted make problem clear possible, , hope worked...
2. sorry english, may have noticed, it's not mothers tongue. trying improve though, if spot mistakes, feel free tell me.
(3. hope code readable, tried keep structured.)
i started arduino programming few days ago, because coworker asked me if wanted use control terrariums in convenient way. well, said yes , don't regret far. until used raspberrypi , cronjob switch lights, didn't work well.
but seems stuck, hope of willing give me advice.
my setup:
- set: http://www.sainsmart.com/sainsmart-mega2560-board-3-5-tft-lcd-module-display-shield-kit-for-atmel-atmega-avr-16au-atmega8u2.html (arduino mega2560 + 3.2 tft touch screen + shield)
- ds1307 timer (sda -> analog 0, sdc -> analog 2)
- 433mhz transmitter control remote sockets (the remote sockets elro ab440s, transmitter 1 of billions of transmitters can buy 1€/$) (data -> pin

what trying do?
- automatically switch lights in terrariums on/off, while simulating different seasons (no light during winter, longest during summer, etc.) -> main reason why don't want use standard time switches, since ususally not allow many different times depending on date
- print buttons on touch screen can manually switch additional remote sockets (e.g. tv, pc, lights, ...)
right now, buttons used in case goes wrong. got 1 button switches in terrariums on, 1 switches off , 1 doesn't far.
my problem:
- timer works fine. lights switched on/off want them to.
- can't use buttons. in examples buttons implemented using infinite while loop, can't use because timer wouldn't work if did. if-functions switch lights not included in while loop controls buttons, if while loop infinite, if-functions never reached.
i guess 1 of problems don't draw buttons during execution of "void loop" function. if that, drawn continously, resulting in flickering buttons. if add "draw buttons" part "void loop"function, doesn't work. can press button, shows red frame around button while pressed, doesn't execute commands.
i included code (with part of timer cut out keep short). important part right @ beginning of void loop function, tried make buttons work.
p.s, - in advance:
1. sorry long post, wanted make problem clear possible, , hope worked...
2. sorry english, may have noticed, it's not mothers tongue. trying improve though, if spot mistakes, feel free tell me.

(3. hope code readable, tried keep structured.)
code: [select]
//include libraries
#include <utft.h>
#include <utouch.h>
#include <utft_buttons.h>
#include <ds1307.h>
#include <rcswitch.h>
//initialise everything
utft myglcd(itdb32s,38,39,40,41);
utouch mytouch(6,5,4,3,2);
utft_buttons mybuttons(&myglcd, &mytouch);
ds1307 rtc(a0,a2);
rcswitch myswitch = rcswitch();
time t;
//declare used fonts
extern uint8_t smallfont[];
extern uint8_t bigfont[];
//--------------setup everything--------------
//setup function
void setup() {
myglcd.initlcd();
myglcd.clrscr();
mytouch.inittouch();
mytouch.setprecision(prec_low);
myglcd.setfont(smallfont);
myglcd.setbackcolor(0,0,0);
mybuttons.settextfont(bigfont);
//draw fixed parts of date , time
myglcd.print("|",175,215);
myglcd.print("|",257,215);
myglcd.drawroundrect(140,208,315,232);
//settings transmitter
myswitch.enabletransmit(8);
myswitch.setrepeattransmit(10);
//status messages
myglcd.drawroundrect(10,80,265,190);
myglcd.print("status roehren reptilien:",20,90);
myglcd.print("status spots reptilien:",20,110);
myglcd.print("status roehren froesche:",20,130);
myglcd.print("status spot froesche:",20,150);
myglcd.print("status nachtlicht leos:",20,170);
//add buttons
int off, on, other, pressed_button;
off = mybuttons.addbutton(10,10,90,50,"aus");
on = mybuttons.addbutton(115,10,90,50,"an");
other = mybuttons.addbutton(220,10,90,50,"sonst");
mybuttons.drawbuttons();
}
//--------------loop function--------------
void loop() {
int off, on, other, pressed_button;
t = rtc.gettime();
while (mytouch.dataavailable()==true) {
pressed_button=mybuttons.checkbuttons();
if (pressed_button==off) {
roehrenrepaus();
roehrenfraus();
roehrenfraus();
spotfraus();
spotrepaus();
}
if (pressed_button==on) {
roehrenrepan();
roehrenfran();
roehrenfran();
spotfran();
spotrepan();
}
}
//--------------timer--------------
//geckos nl
if (t.hour==22 && t.min==02) {
nlleoan();
}
if (t.hour==1 && t.min==00) {
nlleoaus();
}
//january
if (t.mon==1) {
//frogs
if (t.hour==10 && t.min==15) {
roehrenfran();
}
if (t.hour==20 && t.min==45) {
roehrenfraus();
}
if (t.hour==10 && t.min==45) {
spotfran();
}
if (t.hour==20 && t.min==15) {
spotfraus();
}
//other terrariums
//15. - 16.
if (t.date==15 || t.date==16) {
[cut out keep short]
//december
if (t.mon==12) {
if (t.hour==10 && t.min==00) {
roehrenfran();
}
if (t.hour==21 && t.min==00) {
roehrenfraus();
}
if (t.hour==10 && t.min==30) {
spotfran();
}
if (t.hour==20 && t.min==30) {
spotfraus();
}
}
//--------------display date , time--------------
myglcd.print(rtc.getdowstr(format_short),150,215);
myglcd.print(rtc.getdatestr(format_short),190,215);
myglcd.print(rtc.gettimestr(format_short),270,215);
}
//--------------used functions--------------
void roehrenrepan() {
myglcd.print("an ",230,90);
myswitch.switchon("11000", "01000");
delay(1000);
myswitch.switchon("10001", "00100");
delay(1000);
myswitch.switchon("11000", "00100");
}
void roehrenrepaus() {
myglcd.print("aus",230,90);
myswitch.switchoff("11000", "01000");
delay(1000);
myswitch.switchoff("10001", "00100");
delay(1000);
myswitch.switchoff("11000", "00100");
}
void spotrepan() {
myglcd.print("an ",230,110);
myswitch.switchon("11000", "10000");
delay(1000);
myswitch.switchon("10001", "00010");
delay(1000);
myswitch.switchon("11000", "00010");
}
void spotrepaus() {
myglcd.print("aus",230,110);
myswitch.switchoff("11000", "10000");
delay(1000);
myswitch.switchoff("10001", "00010");
delay(1000);
myswitch.switchoff("11000", "00010");
}
void roehrenfran() {
myglcd.print("an ",230,130);
myswitch.switchon("10001", "10000");
}
void roehrenfraus() {
myglcd.print("aus",230,130);
myswitch.switchoff("10001", "10000");
}
void spotfran() {
myglcd.print("an ",230,150);
myswitch.switchon("10001", "01000");
}
void spotfraus() {
myglcd.print("aus",230,150);
myswitch.switchoff("10001", "01000");
}
void nlleoan() {
myglcd.print("an ",230,170);
myswitch.switchon("11001", "10000");
}
void nlleoaus() {
myglcd.print("aus",230,170);
myswitch.switchoff("11001", "10000");
}
if buttons giving issues, can try library, works utft , utouch. search tft_extension in either forum or arduino playground. included plenty of examples. give try.
Arduino Forum > Using Arduino > Programming Questions > Mega2560 + 3.2 TFT Touch, automated terrarium control + manual buttons
arduino
Comments
Post a Comment