2.8 in ili9341_touch display code differences vs ili9341_t3 library

Status
Not open for further replies.
Thanks for the interrupt idea. I think that will help to reduce any erratic response to the touch function. On another note, I am having trouble with the original external button input function of Paul's Audio Workshop (Part_03_02_Fourier_Transform) listed below.

button0.update();
button1.update();
button2.update();

// Left button starts playing a new song
if (button0.fallingEdge()) {
mixer1.gain(2, 0.0);
mixer1.gain(3, 0.0);
fileNumber = fileNumber + 1;
if (fileNumber >= 4) fileNumber = 0;
playMem1.stop();
playSdWav1.play(filenames[fileNumber]);
mixer1.gain(0, 0.5);
mixer1.gain(1, 0.5);
}

I am now transferring these mode inputs to the XPT2046 display touch mode buttons with different variable names (i.e. button0 = audmode, button1 = seqmode, etc.). The only renamed mode that does not work is button0 with executing "playSdWav1.play(filenames[fileNumber]);". What I am wondering is if the SD.h or audio.h library expects the specific "button0" variable to be passed instead of my new variable name "audmode". If not, maybe it has more to do with the button0.update(); function as it is not being used due to no external switch input. Any ideas on this?
 
That looks like the existing code - triggering only when button0.fallingEdge is detected - How does the replacement code look?
 
The new code is shown below with no reference to the button0.update(); requirement, just Audmode display button going low.

// Audio button starts playing a new song
if (Audmode == (0)) {
mixer1.gain(2, 0.0);
mixer1.gain(3, 0.0);
fileNumber = fileNumber + 1;
if (fileNumber >= 4) fileNumber = 0;
// playMem1.stop();
playSdWav1.play(filenames[fileNumber]);
mixer1.gain(0, 0.5);
mixer1.gain(1, 0.5);
} //End automode sampling

The following code was used from the TouchTest example:

void loopB() {
TS_Point p = ts.getPoint();
Serial.print("Pressure = ");
Serial.print(p.z);
if (ts.touched()) {
Serial.print(", x = ");
Serial.print(p.x);
Serial.print(", y = ");
Serial.print(p.y);
}
Serial.println();
// delay(100);
delay(30);
}

The Audmode is set low in the touch screen code qualified by x and y as follows (main loop):

//Check for mode touch
if (ts.touched()) {
TS_Point p = ts.getPoint(); //Get touch points
Serial.print("Pressure = "); //Print position, pressure
Serial.print(p.z);
Serial.print(", x = ");
Serial.print(p.x);
Serial.print(", y = ");
Serial.print(p.y);
delay(30);
Serial.println();

// draw the verticle mode buttons and detect mode selection
//void fillRect(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint16_t color);

if (2500 < p.x && p.x < 3650) { //If touch is on mode button line
tft.fillRect(5, 200 - height, 20, 290, ILI9341_BLACK);
tft.fillRect(45, 200 - height, 20, 290, ILI9341_BLACK);
tft.fillRect(85, 200 - height, 20, 290, ILI9341_BLACK);
tft.fillRect(125, 200 - height, 20, 290, ILI9341_BLACK);
tft.fillRect(165, 200 - height, 20, 290, ILI9341_BLACK);
tft.fillRect(205, 280 - height, 20, height, ILI9341_WHITE);

if (3050 < p.y && p.y < 3700){ //Set audio mode button 1 if in range
tft.fillRect(5, 290 - height, 20, height, ILI9341_WHITE);
Audmode = 0;
Seqmode = 1;
Ranmode = 1;
Cnvmode = 1;
Hltmode = 1;
Serial.print("Audio mode=");
Serial.println(Audmode);
// delay(200);
}
}
 
Last edited:
In the last portion of the code above, the line "Audmode = 0;" The other modes are set to a "1" (off).
 
Last edited:
Side comment: Sure wish code fragments were in code tags so you can better see the flow ...

Not sure what you are asking? Are you asking how to process the touch information, such that if you click on a logical button, it only is processed once?

So it looks like if you get any touch event that has the x,y within some rectangle than it turns that variable on, not sure where it gets turned off and not sure how/when it stops....

I have not yet done any touch input for my current stuff, (well monitor and also probably robot control), but I have in the past, but was using Adafruit version of display with the different touch sensor. Also the last time I did it was on Intel Edison using Eclipse... But will soon.

What my buttons typically did, was to detect the touch, and track the touch. If the touch is inside an object, such as a button, I will show the button in it's depressed state (could change color, or highlight changes.. or?), and only if when I release the touch I am still inside of the object, will I then process the command for the button.

I also used to have some things like sliders and the like, that if I clicked on it and dragged, it will track my movement, but if I moved too far outside of the object in the other direction it would release the object...

But again not sure what you are asking.
 
Not sure if it is interesting or not, but I hacked up an old test program that I would probably rewrite, but it had some buttons and slider like objects, and I hacked it up to use the XPT... controller. It is a multi-tab sketch. At the time I was working on maybe abstracting away which display... So the code is convoluted.
But it sort of works... Nothing is hooked up to buttons here... Except I think the UP/Down buttons sort of go to new displays...
This code was originally some stuff I was doing for my Teensy DIY XBEE remote control, where I have real sliders, keypad, 3 axis joysticks...
TD-Assembled-with-shields.jpg


The file display.h has the defines for which pins I am using on my display and touch...

Again it ain't much. I am sure there are much better libraries available
 

Attachments

  • Teensy_ILI9341_Touch-170203b.zip
    17.5 KB · Views: 70
Sorry about the code fragments. I have to figure out how to create code tags on this form. Guess I haven't read enough of the procures. I will take a look at your code example. To answer your two questions relative to my code, they are:

Question - Not sure what you are asking? Are you asking how to process the touch information, such that if you click on a logical button, it only is processed once? Answer - I was just using a delay after selection, but your idea about waiting until the touch is released before executing the selections.

Question - So it looks like if you get any touch event that has the x,y within some rectangle than it turns that variable on, not sure where it gets turned off and not sure how/when it stops.... Answer - The selection detected turns off all other non-selected modes. That works okay.

The original issue was just trying to figure out why the audio mode did not get selected like the other modes and I thought it might have something to do with the SD card library interaction with the button0 variable instead of the new Audmode. But if executing the line "playSdWav1.play(filenames[fileNumber]);" in the original code should play the SD card music, then it must be something else. I'll keep searching the code for an answer.

Turns out I am going to use XBEE also because of the net relay feature so thanks for the example. I'm sure I have a lot to learn on that as far as formating command/data packets.

Thanks much for your help.
 
Code Tags: the '#' hash icon or wrap like this ( I hit the comment cloud and change QUOTE to CODE on both ends ):
code.PNG
 
Status
Not open for further replies.
Back
Top