SR-04 data to TFT under touch screen button


hi,

i trying calculate passed time between 2 ultrasonic readings (ultrasonic values 15 , 35). far value 0.
sensor attached fixed moving bar, goes , down, , want calculate time of upward movement after button1 has been pressed.

code: [select]


#include "rbd_timer.h"
#include <lcdtft.h>
#include <lcdtp.h>
#include "font.h"
#include "button.h"
#include "spi.h"
#include <ultrasonic.h>

#define backcolor 0xffff
#define  delay_start   >15       // or low depending on blink detection logic
#define  delay_end   >35   // inverse of above
tftlcd tft;
ultrasonic ultrasonic(7,4);
rbd::timer timer;
//font class object font
font  font;
long start, duration;
//touchuscreem tp class object tp
tp tp;
//two button class object is  button1,button2
button  button1,button2,button3,button5,button6,button7,button8;
void setup()
{
  //tft initialization
   tft.begin();
   analogwrite(6, 255);
   serial.begin(115200);
   timer.settimeout(3000);
   //lcd clear screen, backcolor
   tft.clear(backcolor);
   serial.begin(9600); 
   serial.print(ultrasonic.ranging(cm));
   //set text area upper left corner (10, 10), lower right corner (200,200), if color null or r0 g0 b0(black), not set text color
   font.set_txt(10,10,200,100,tft.rgb_to_565(255,255,255));
   
   //set text font color
   font.set_fontcolor(tft.rgb_to_565(0,0,255));
   //displays string

   
   //to modify button size
   button1.resetsize(100,100);
   //draw first round button1
   button1.drawbutton(5,130,1,"testit");
 
 
   button2.resetsize(100,100);
   button2.drawbutton(110,130,1,"harjoitus");
 
   button3.resetsize(100,100);
   button3.drawbutton(215,130,1,"asetukset");
   
   

}

void loop()
{
 
       
       //check touch current state detection
      tp.pen_down();
     
      //the touch screen touch
      if(tp.flag&&tp.y_val&&tp.x_val)
      {
        //check whether pressing first button
     if (button1.istouch(tp.x, tp.y))
      {

        tft.clear(backcolor);
        font.set_txt(10, 10, 200, 100, tft.rgb_to_565(255, 255, 255));
        font.set_fontcolor(tft.rgb_to_565(0, 0, 255));
        font.lcd_string("odotetaan..");
        float mitta1 = (ultrasonic.ranging(cm));
       
       
     
         if(mitta1>15)  ;
        timer.restart();
         
         if(mitta1>35);
        int duration = timer.getvalue();

     
       
       font.set_txt(200, 10, 100, 100, tft.rgb_to_565(255, 255, 255));
       font.set_fontcolor(tft.rgb_to_565(0, 0, 255));
       font.lcd_int(duration);
       
        button1.resetsize(100, 100);
        button1.drawbutton(5, 130, 1, "nollaa");
        button2.resetsize(100, 100);
        button2.drawbutton(110, 130, 1, "harjoitus");
        button3.resetsize(100, 100);
        button3.drawbutton(215, 130, 1, "asetukset");
       
       }
      }   
}   


     






Arduino Forum > Using Arduino > Sensors > SR-04 data to TFT under touch screen button


arduino

Comments