Hi (this is my first post)
I wrote a programme for arduino mega and ILI9341 touchscreen LCD with the V2.2 schield. Everything was good and works alone. But since i assembled the drawHomeScreen it stopped working.
Is it a limited number of print on the LCD?
Because when i comment just one If { ... } in the main loop it works. And it doesn't depend on wich if i comment... meaning that they work all but not all together.
Could somebody help me ?
void loop() {
if(page==0){
myFiles.load(0, (240-103)/2, 320, 240, "Logo2.raw", 10, 0);
delay(2000);
myGLCD.clrScr();
page=1;
}
if(page==1){
drawHomeScreen1();
if(touchButtons(160,210,"Jeux")==true){
Serial.println("Jeux appuiye");
page=page+1; // Num page bouton
myGLCD.clrScr();
}
}
if(page==2){
drawHomeScreen2();
if(touchButtons(160,210,"Commencer")==true){
Serial.println("Commencer appuiye");
page=3;
myGLCD.clrScr();
}
}
if(page==3){
drawHomeScreen3();
if(touchButtons(290,210,"OK")==true){
Serial.println("Ok appuiye");
page=4;
myGLCD.clrScr();
}
if(touchButtons(40,210,"Aide")==true){
Serial.println("aide appuiye");
page=page+100; // Num page Aide
myGLCD.clrScr();
}
}
if(page==4){
drawHomeScreen4();
if(touchButtons(260,210,"Monter")==true){
Serial.println("Monter appuiye");
page=5;
myGLCD.clrScr();
}
if(touchButtons(70,210,"Conseil")==true){
Serial.println("Conseil appuiye");
page=page+100; // Num page conseil
myGLCD.clrScr();
}
}
if(page==5){
drawHomeScreen5();
if(touchButtons(290,210,"OK")==true){
Serial.println("Ok appuiye");
page=7;
myGLCD.clrScr();
}
if(touchButtons(40,210,"Aide")==true){
Serial.println("aide appuiye");
page=page+100; // Num page Aide
myGLCD.clrScr();
}
}
if(page==6){
drawHomeScreen6();
if(touchButtons(160,120,"Faire un noeud")==true){
Serial.println("Faire un noeud appuiye");
page=6;
myGLCD.clrScr();
}
if(touchButtons(160,200,"Montage termine")==true){
Serial.println("Montage termine appuiye");
page=7; // Num page Aide
myGLCD.clrScr();
}
}
if(page==7){
drawHomeScreen7();
if(touchButtons(160,210,"Fin")==true){
Serial.println("fin");
page=0;
myGLCD.clrScr();
}
}
}
LCD_Montanche_1.ino (10.2 KB)
Hi CamilleR —
Could you clarify what happens when you run the code? For example, do you see it not display anything, display the wrong page, the buttons not respond to touch presses or the buttons seem to lead to the wrong page, etc.?
There are a couple things in your code that are worth keeping in mind as they could lead it to run differently than you might expect:
- The
touchButtons()
calls in your loop() don’t appear to be incorporating an “edge detect”. In general, you will only want to take action on a button press (leading to another page) if the button has been released. So, you may want to consider only advancing the page when you see the touchButtons()
was true before but false now.
- Without an edge detect on your touch handling, it is possible that pressing on the button on your first home screen is quickly running through the next couple pages (as some of your buttons happen to be in the same place on different pages)
- You probably don’t want to continuously call the
drawHomeScreen()
every time you go through the loop. You should consider creating another variable that indicates whether the page has changed. If the page has changed, call the drawHomeScreen()
, otherwise, just look for touch presses.
Hi Impulsive
Thank you very much for your answer.
First thing you aked for is what happend when it doesn't work. I only got a white screen and then a black screen coming from the right going to the left then a whit screen and it blinks like that without stopping.
Then come the advise you give me. For the call of the drawHomescreen , Nice advice !! i it works really better when it works.
I wrote this new version of the program. But the thing is always the same... When every line in the main loop with drawHomeSreen1234...() are uncomment, it blinks as discribe upper. And when i comment one of these line (doesn't matter which one) then it works... So I am really lost
And for the touchboutton() the function works really well like that and I did not really understand what you mean by "edge detect" Do you mine an algorythme that detect corner of the bouton?
Again thank you for your answer
I wasn't thinking that peaple could be so reactif... I Like it!!!
LCD_Montanche_1.ino (10.5 KB)
Ok you may be also right with the touchButton() because when I comment one of the If(touchBoutton()) it works... code to explain
LCD_Montanche_1.ino (10.6 KB)
Glad to hear the drawHomeScreen()
is working better. Your check for page!=currentPage
will definitely help.
As for the edge detect, it is just another way to say look for a change from on-to-off or off-to-on. Currently, you are currently checking to see if touchButtons()
is true, and if so, advancing your page assignment, which is doing a "level sensitive" check, not an "edge detect". If you do a level-sensitive check, then your program runs the risk of continuously taking a number of actions in a row because it is running through all of your if (currentPage==...)
actions in the time that your finger was pressing the button. In most cases you only want a button to take action when you release it, which ensures that it doesn't inadvertently "run through" your code.
To use edge detection here, what you would do is determine if the button touch was true previously, but now the button touch is false. Only when you see this (previousTouch && !currentTouch
) condition would you update the page.
However, one problem you will run into is that your touchButtons()
code currently attempts to do two things: checking the touch status and then also checking for a "hit" within the specified button rectangle. By combining these, it will be much harder to do an edge detect.
So, I would recommend you split the touchButtons()
functionality into two functions: touchRelease()
and a touchInButton()
. The first function just checks to see if dataAvailable
transitioned from true to false (ie. detecting that you released/finished your touch), and only returning true if this transition happened. The second function touchInButton()
takes the most recent touch coordinate (new parameters) and the button positions (as you currently provide to touchButtons
). Return true only if the touch coordinate is within your button rectangle.
When making your touchRelease()
function, you'll probably want to use a global variable to keep track of the previous state of myTouch.dataAvailable()
.
With the above, your main loop can call touchRelease()
once, and if true, it can then check for all of the buttons by calling touchInButton()
, which will test the most recent touch against all of the buttons that you want to check.
good luck!
My function ButtonSurbrillance() Already take care of the waiting before the stop pushing button with the while (dataavailable()).
But i still tried your method and now I can't see my image (page 0) neither the button on page 1 is printed nor touchable
what did i miss? Is it what you was thinking of?
LCD_Montanche_2.ino (11 KB)
I finally find the problem but I did not understood why it was one
In the main loop I had written this
else if(currentPage==6){
if(touchButtons(160,120,"Faire un noeud")){
Serial.println("Faire un noeud appuiye");
page=7;
myGLCD.clrScr();
}
if(touchButtons(160,200,"Montage termine")==true){
Serial.println("Montage termine appuiye");
page=7;
myGLCD.clrScr();
}
}
And when I change the Serial.print just deleting "appuiye" as the following code it starts to work well... WTF???
else if(currentPage==6){
if(touchButtons(160,120,"Faire un noeud")){
Serial.println("Faire un noeud");
page=7;
myGLCD.clrScr();
}
if(touchButtons(160,200,"Montage termine")==true){
Serial.println("Montage termine");
page=7;
myGLCD.clrScr();
}
}
So thank you very much for all Impulsive!!!
One last question What is the difference between several if and one if and several else if?