Need to wait in loop until button on touchscreen is clicked


hi, i'm new programming maybe question simple (i hope :d)

i have arudino mega 3.2" touchscreen. connected battery , pressure sensor. arduino reads prints voltage , pressure every 1000 ms (i put delay(1000) @ end of loop).

then, added button says "save&stop" (i want save data sd card later i'm not there yet). when button pressed new window question "do want save , stop?" , 2 buttons "yes" , "no" open.

the problem is, need run loop continuously acquire data. when loop starts on window, opened gets overwritten stuff, implemented in loop.

is there trick how run these 2 functions @ same time? without overwriting?


code: [select]


#include <utft.h>
#include <itdb02_touch.h>
#include <utft_buttons_itdb.h>

extern uint8_t smallfont[];
extern uint8_t bigfont[];
extern uint8_t dingbats1_xl[];

utft myglcd(itdb32wc, 38, 39, 40, 41);
itdb02_touch mytouch(6, 5, 4, 3, 2);
utft_buttons mybuttons(&myglcd, &mytouch);

//pressure values:
int pressurepin = a0;
int pressurevalue = 1;
int pressurevalue1;
double pressurevalue2;
double p1 = 0;        //variable conversion kpa. not yet calibrated.
double p2 = 1;        //variable conversion kpa. must not = 0!

//voltage values:
int voltagepin = a2;
double voltagevalue = 1;
double voltagevalue1;
int divider = 10;

//buttons
int butstop, pressed_button, buty, butn;


void setup() {
  myglcd.initlcd();
  myglcd.clrscr();
  myglcd.setfont(bigfont);
  mytouch.inittouch(1);
  mytouch.setprecision(prec_medium);
  mybuttons.settextfont(bigfont);
  mybuttons.setsymbolfont(dingbats1_xl);
  myglcd.setcolor(vga_white);
  myglcd.print("pressure", 5, 30);
  myglcd.print("kpa", 100, 60);
  myglcd.print("voltage", 165, 30);
  myglcd.print("v", 280, 60);
  myglcd.setcolor(vga_white);
  myglcd.drawrect(1, 20, 157, 80);
  myglcd.drawrect(160, 20, 319, 80);
  butstop = mybuttons.addbutton( 60, 100, 200, 40, "save & stop");
  mybuttons.setbuttoncolors(vga_black, vga_gray, vga_white, vga_blue, vga_aqua);
  mybuttons.drawbuttons();
}

void loop() {
//buttons: here main problem?!!
while(mytouch.dataavailable() == true)
  pressed_button = mybuttons.checkbuttons();
 
  if (pressed_button == butstop){
    myglcd.setcolor(vga_yellow);
    myglcd.fillrect(5, 95, 315, 235);
    myglcd.setcolor(vga_black);
    myglcd.print("do want to", 10, 100);
    myglcd.print("save , stop?", 10, 120);
    buty = mybuttons.addbutton(  10, 160, 50, 40, "yes");
    butn = mybuttons.addbutton( 160, 160, 50, 40, "no");
    mybuttons.setbuttoncolors(vga_black, vga_gray, vga_white, vga_blue, vga_aqua);
    mybuttons.drawbuttons();
    while(mytouch.dataavailable() == false) {};
    /*???????? need check if button pressed therefore need jump out of loop...
i have problem checks every 1000ms whether button pressed :( */
 
  }
 
//get , print pressure value every 0.5s
  myglcd.setcolor(vga_black);                       //overwrite previous values black box.
  myglcd.fillrect(5, 55, 99, 65);
  pressurevalue = analogread(pressurepin);
  //serial.println(pressurevalue)
  pressurevalue1 = pressurevalue - p1;              //for conversion kpa
  if (pressurevalue1 < 0) {
    pressurevalue2 = 0;                             //only values higher 0 shown.
  } else {
    pressurevalue2 = pressurevalue1 / p2;          //conversion kpa
  }
  string pressurevalstr = string(pressurevalue2); //conversion string
  myglcd.setcolor(vga_white);
  myglcd.print(pressurevalstr, 5, 60);

//get , print voltage value every 0.5s
  myglcd.setcolor(vga_black);
  myglcd.fillrect(165, 55, 279, 65);              //overwrite previous values black box.
  voltagevalue = analogread(voltagepin);
  //serial.println(voltagevalue);
  voltagevalue1 = voltagevalue * divider;       //multiply voltage divider value.
  string voltagevalstr = string(voltagevalue1); //conversion string
  myglcd.setcolor(vga_white);
  myglcd.print(voltagevalstr, 165, 60);
  delay(1000);
}


thanks in advance! :)

create global boolean define whether "save , stop" screen posted.

when button pressed, if "save , stop" screen posted, 1 thing. if not, else.


Arduino Forum > Using Arduino > Programming Questions > Need to wait in loop until button on touchscreen is clicked


arduino

Comments

Popular posts from this blog

DHT11 Time out error using v0.4.1library

Sketch upload fails with Java error (___REMOVE___/bin/avrdude)!

Arduino Uno + KTY81/210 temperature sensor