Hello everyone, this is my first post
And here is my problem:
I am building a car gear position indicator, and would like to display the gear on a TFT display.
I would like to make it work so that the gear doesn't constantly "flash" or is written every time the program goes thru the loop, but that the indicated gear stays the same until changed.
In the attachment you can see the setup, when a button is pushed, it should indicate the corresponding gear, and if no buttons are pushed, it should indicate neutral ( N ).
Here is the code :
int first = 0;
int second = 0;
int third = 0;
int fourth = 0;
int fifth = 0;
int reverse = 0;
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9340.h"
#if defined(__SAM3X8E__)
  #undef __FlashStringHelper::F(string_literal)
  #define F(string_literal) string_literal
#endif
// These are the pins used for the UNO
#define _sclk 13
#define _miso 12
#define _mosi 11
#define _cs 10
#define _dc 9
#define _rst 8
//Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _mosi, _sclk, _rst, _miso);
Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _rst);
void setup() {
 pinMode(2, INPUT);
 pinMode(3, INPUT);
 pinMode(4, INPUT);
 pinMode(5, INPUT);
 pinMode(6, INPUT);
 pinMode(7, INPUT);
Â
 Serial.begin(9600);
Â
Â
  tft.begin();
}
void loop() {
tft.fillScreen(ILI9340_BLACK);
 tft.setRotation(1);
 tft.setCursor(0, 0);
 tft.setTextColor(ILI9340_GREEN);
 tft.setTextSize(14);
Â
 first = digitalRead(2);
 second = digitalRead(3);
 third = digitalRead(4);
 fourth = digitalRead(5);
 fifth = digitalRead(6);
 reverse = digitalRead(7);
/////////////////////////////////////////////////////////////
 do
 { tft.println("1st");
Â
 } while (first == HIGH);
 //////////////////////////////////////////////////////////
Â
 if (second == HIGH)
 {
  tft.println("2nd");
 }
 //////////////////////////////////////////////////////////
Â
else if (third == HIGH)
 {
  tft.println("3rd");
 }
 //////////////////////////////////////////////////////////
Â
 else if (fourth == HIGH)
 {
  tft.println("4th");
 }
 //////////////////////////////////////////////////////////
Â
else if (fifth == HIGH)
 {
  tft.println("5th");
 }
Â
 //////////////////////////////////////////////////////////
Â
else if (reverse == HIGH)
 {
  tft.println("R");
 }
Â
 //if (first== LOW,second== LOW,third== LOW,fourth== LOW,fifth== LOW,reverse == LOW)
else
 {
  tft.println("N");
 }
 //////////////////////////////////////////////////////////
 Â
//delay();
}
Did I approach the problem in the right way ? How to keep the gear from "flashing" until there is a change in gear ?
Any suggestrion, comments, ideas are welcome!
Thanks