I've seen in sketches with TFT displays flickeron_btn and flickeroff_btn comands.
Could someone explain what they do and how they should be used.
I have tried googling the terms but found nothing that helps me.
Cheers John
I've seen in sketches with TFT displays flickeron_btn and flickeroff_btn comands.
Could someone explain what they do and how they should be used.
I have tried googling the terms but found nothing that helps me.
Cheers John
Can you provide some context / links?
Just various articles using touch screens.
This example is from another forum article and the person talks about trying to add flicker.
Here below is someones code that has a number of screens and changes colours using the touch screen.
Before it gets to the Void setup there are the flickeron_btn, flickeroff_btn, mentioned.
#include <Adafruit_GFX.h> // Touch Screen
#include <MCUFRIEND_kbv.h> // Touch Screen
MCUFRIEND_kbv tft; // Touch Screen
#include <TouchScreen.h> // Touch Screen
#define MINPRESSURE 200 // Touch Screen
#define MAXPRESSURE 1000 // Touch Screen
int Actualtemperature = (17); // Touch Screen
//int SetTemperature = (18); // Touch Screen
int Humidity =(55); // Touch Screen
char DisplayTemp[5]; // Touch Screen
//+++++++++++++++++++++++++++++++
#include <math.h>
//+++++++++++++++++++++++++++++++
#include <Adafruit_Sensor.h> // Sensor
#include <DHT.h> // Sensor
#include <DHT_U.h> // Sensor
#define DHTPIN 39 // Sensor
#define DHTTYPE DHT22 // Sensor
DHT_Unified dht(DHTPIN, DHTTYPE); // Sensor
uint32_t delayMS;
int SetTemperature = (4); //The initial setting of the required tempreture is 4C
#define ledPin 45 // Sensor
//+++++++++++++++++++++++++++++++
int J=(1);
float T = (0.9);
// copy-paste results from TouchScreen_Calibr_native.ino
const int XP=6,XM=A2,YP=A1,YM=7; //240x320 ID=0x9341
const int TS_LEFT=178,TS_RT=938,TS_TOP=929,TS_BOT=173;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
int pixel_x, pixel_y; //Touch_getXY() updates global vars
bool Touch_getXY(void)
{
TSPoint p = ts.getPoint();
pinMode(YP, OUTPUT); //restore shared pins
pinMode(XM, OUTPUT);
bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE);
if (pressed) {
// most apps use Portrait or Landscape. No need for all 4 cases
switch (tft.getRotation()) {
//
case 1:
pixel_x = map(p.y, TS_TOP, TS_BOT, 0, tft.width());
pixel_y = map(p.x, TS_RT, TS_LEFT, 0, tft.height());
break;
}
}
return pressed;
}
Adafruit_GFX_Button on_btn, off_btn, flickeron_btn, flickeroff_btn, decrease_btn, increase_btn;
Adafruit_GFX_Button decrease_btn, increase_btn;
// easier to handle a list of button pointers
Adafruit_GFX_Button *screen0[] = {&decrease_btn, &increase_btn, NULL };
int flag = 0, screen = 0;
// INITIALISE GPIO, TOUCH, TFT, BUTTONS
// ------------------------------------------------------------------------------
void setup()
{
pinMode ( ledPin, OUTPUT); // Sensor
Serial.begin(9600); // Sensor
dht.begin(); // Sensor
sensor_t sensor; // Sensor
dht.temperature().getSensor(&sensor); // Sensor
dht.humidity().getSensor(&sensor); // Sensor
delayMS = sensor.min_delay / 1000; // Sensor
digitalWrite(ledPin,HIGH); // Sensor
tft.begin(tft.readID());
tft.setRotation(1); //LANDSCAPE
decrease_btn.initButton(&tft, 250,220, 120, 40, TFT_BLACK, TFT_BLUE, TFT_BLACK, "DECREASE", 2);
increase_btn.initButton(&tft, 80, 220, 120, 40, TFT_BLACK, TFT_RED, TFT_BLACK, "INCREASE", 2);
tft.fillScreen(TFT_BLACK);
decrease_btn.drawButton(false);
increase_btn.drawButton(false);
tft.setCursor(10,20);
tft.setTextColor(TFT_WHITE);
tft.setTextSize(2);
tft.print("Set Temperature: ");
tft.setCursor(285,20); // Postion of "C" for Set Temperature
tft.print ("C");
tft.setCursor(250,20);
// tft.print(SetTemperature);
tft.setCursor(10,60);
// tft.setTextSize(2);
tft.print("Act Temperature: ");
tft.setCursor(275,60); // Postion of "C" for Actual Temperature
// tft.print ("C");
tft.setCursor(10,100);
tft.print("Humidity :");
tft.setCursor(275,100);
tft.print ("%");
}
// ------------------------------------------------------------------------------
void loop(void)
{
//++++++++++++++++++++++++++
//delay(delayMS); // Sensor Delay between measurements.
sensors_event_t event; // Sensor Get temperature event and print its value.
dht.temperature().getEvent(&event); // Sensor
if (isnan(event.temperature)) {( T = 99.0 );}
else {
(T = event.temperature);
}
//++++++++++++++++++++++++++
if (T >= SetTemperature) // Sensor check temperature against required temperature
{ (digitalWrite(ledPin,LOW) ); } // Radiator send signal to turn off
else {
digitalWrite(ledPin, HIGH);} // Radiator send signal to turn on
//++++++++++++++++++++++++++
tft.setTextColor(TFT_BLACK);
tft.setCursor(250,60);
// Clear old Temperature
tft.setCursor(250,60);
tft.setTextColor(TFT_WHITE);
tft.print(DisplayTemp); // Print new Temperature
Serial.println ( DisplayTemp );
//++++++++++++++++++++++++++
// tft.println ("C");
// tft.println ("");
dht.humidity().getEvent(&event); // Sensor Get humidity event
if (isnan(event.relative_humidity)) { event.relative_humidity = (0); } // Sensor
// tft.print(" Humidity :");
dht.humidity().getEvent(&event);
// tft.print(event.relative_humidity); // Get actual Humidity and print to Screen
// tft.println ("%");
static uint16_t color = TFT_BLACK;
// READ TOUCH
if (screen == 0) {
update_button_list(screen0); //process all buttons
if (decrease_btn.justPressed())
{ tft.setCursor(250,20);
tft.setTextColor(TFT_BLACK);
tft.print(SetTemperature);
Serial.println (SetTemperature);
tft.setTextColor(TFT_WHITE);
tft.setCursor(250,20);
(SetTemperature = SetTemperature - 1);
tft.print(SetTemperature);
}
if (increase_btn.justPressed())
{ tft.setCursor(250,20);
tft.setTextColor(TFT_BLACK);
tft.print(SetTemperature);
(SetTemperature = SetTemperature +1); // Raise The tempreture
tft.setTextColor(TFT_WHITE);
tft.setCursor(250,20);
tft.print(SetTemperature);
Serial.println (SetTemperature);
}
}
}
/* update the state of a button and redraw as reqd
*
* main program can use isPressed(), justPressed() etc
*/
bool update_button(Adafruit_GFX_Button *b, bool down)
{
b->press(down && b->contains(pixel_x, pixel_y));
if (b->justReleased())
b->drawButton(false);
if (b->justPressed())
b->drawButton(true);
return down;
}
/* most screens have different sets of buttons
* life is easier if you process whole list in one go
*/
bool update_button_list(Adafruit_GFX_Button **pb)
{
bool down = Touch_getXY();
for (int i = 0 ; pb[i] != NULL; i++) {
update_button(pb[i], down);
}
return down;
}
void draw_button_list(Adafruit_GFX_Button **pb)
{
tft.fillScreen(TFT_BLACK);
for (int i = 0 ; pb[i] != NULL; i++) {
pb[i]->drawButton(false);
}
}
My link to the other article does not work for me.
here it is you could copy and paste.
https://forum.arduino.cc/t/please-help-with-2-8-spi-display-ili9341/507522/44