[Help] Creating a menu for non touch TFT Screen

Hello everyone.

I am an owner of arduino uno. I have written a code for monitoring voltage changes. It is all displayed on the TFT screen with a graphic style. What i need is also to include a current monitoring, the hardware isnt the problem. What i cannot think how to codea menu for the display to show the voltage diagram. I want to make a two way scrolling menu, forward and backwards, when a button is pressed to display lets say the voltage graph, when pressed the forward button the current when pressed forward again another function.

Thank you for reading, looking forward to reading your replies.

Best regards ~Riste

You can make a simple menu with case statements. just make sure you only run the things you need to per screen otherwise it will slow down your processing time.

If you need to monitor both diagrams with real time values, you can make your variables volatile, but again it may slow things down if you have too many things running.

Hi HazardsMind, the way my graphic works is that for every sensor value it prints a line with a mapped value height, as far as i know i think that "case" menu wont work cuz everytime the code checks if the button is pressed or not it'll restart the whole function a.k.a. graphic so i wont get the graphic to be displayed or im wrong and i dont fully understand the switch function xD. Thank you for your reply.

Post your code as either an attachment (.ino file) or in code tags( of which can be found above the smiley faces as the # button)

#include <TFT.h>  
#include <SPI.h>
 #include <SD.h>
 
#define cs   10
#define dc   9
#define rst  8  


TFT TFTscreen = TFT(cs, dc, rst);


int xPos = 0;

void setup(){
  
  Serial.begin(9600);

 
  TFTscreen.begin();


  TFTscreen.background(250,200,200); 
  

}

void loop(){

  int sensor = analogRead(A0);
  int drawHeight = map(sensor,0,1023,11,TFTscreen.height()-5);
   int sensor1 = analogRead(A1);
  int drawHeight1 = map(sensor1,0,1023,11,TFTscreen.height()-5);
  
  
  Serial.println(drawHeight);
  
  
  TFTscreen.stroke(0,255,255);
 
   
   TFTscreen.line(xPos+10, TFTscreen.height()-drawHeight, xPos+10, TFTscreen.height()-10);
  
    TFTscreen.stroke(0,0,0);
    TFTscreen.text("^", 8, 8);
    
    TFTscreen.text(">", 153, 115);
    
    

    
    
    
  TFTscreen.stroke(0,0,0); 
  TFTscreen.line(0, 118, 158, 118); 
  TFTscreen.line(10, 11, 10, 127);
  if (xPos >= 150) {
    xPos = 0;
    TFTscreen.noStroke();
    TFTscreen.fill(250,200,200); 
    TFTscreen.rect(11,0,150,118); 
      } 
  else {

    xPos++;
  }

  delay(50);
}

if (xPos >= 150) {
xPos = 0;
TFTscreen.noStroke();
TFTscreen.fill(250,200,200);
TFTscreen.rect(11,0,150,118);
}
else {

xPos++;
}

Why are you constantly redrawing the lines? Only when you get a new value should the line change.

When you use the case statement, your "graphs" should be within a while loop, this way only the things related to that graph should be running and not everything. You could also use an Interrupt on the button to change the case.

On second thought, how many screens are you switching between, you might not even need case statement, just an IF/ELSE statement.

The line is constantly drawn cuz i want to compare the changes with the time, so if the voltage is constant i want to see it constant if theres a minor change i want to see the minor change. Its just 2 screens now, voltage and current readings, and hmm seems i have no idea how to code that switch thing and make a loop within.

And the code u asked about, is to refresh the screen when the line reaches the end of the screen i think x)

Where is the button that you want to use the switch the screens?

For the button I would use an interrupt routine that looks for the button state as either "rising" or "falling" (depending on how the button is wired). Then in the interrupt function, you would increment a counter.

For the switch statements, you could have: ( you might not need the while loop)
switch( counter % 2 )
{
case 0:
/* Voltage stuff */
break;

case 1:
/* Current stuff */
break;
}

I would like to use a push button, so i could read a high and low i guess instead rising and lowering... hmm thats a nice idea ill look more into it, thank you very much.

Rising is the transition from low to high, and falling is high to low.
AttachInterrupt Look that the pins used for the interrupts, because there are only so many per board type, and the pins a very specific.

Hah thats very interesting function, even though i dont get it ill struggle more around it! Thank you very much i really appreciate your help kind sir! ill try to solve the problem eventually :stuck_out_tongue:
Oh and i have an Uno so its only pins 2 and 3 :stuck_out_tongue: