Skip to content

Debug errors and optimize code #3620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 1 addition & 21 deletions User_Setup_Select.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,24 +281,4 @@
#define TFT_DRIVER 0x0000
#endif

// These are the pins for ESP8266 boards
// Name GPIO NodeMCU Function
#define PIN_D0 16 // GPIO16 WAKE
#define PIN_D1 5 // GPIO5 User purpose
#define PIN_D2 4 // GPIO4 User purpose
#define PIN_D3 0 // GPIO0 Low on boot means enter FLASH mode
#define PIN_D4 2 // GPIO2 TXD1 (must be high on boot to go to UART0 FLASH mode)
#define PIN_D5 14 // GPIO14 HSCLK
#define PIN_D6 12 // GPIO12 HMISO
#define PIN_D7 13 // GPIO13 HMOSI RXD2
#define PIN_D8 15 // GPIO15 HCS TXD0 (must be low on boot to enter UART0 FLASH mode)
#define PIN_D9 3 // RXD0
#define PIN_D10 1 // TXD0

#define PIN_MOSI 8 // SD1 FLASH and overlap mode
#define PIN_MISO 7 // SD0
#define PIN_SCLK 6 // CLK
#define PIN_HWCS 0 // D3

#define PIN_D11 9 // SD2
#define PIN_D12 10 // SD4

6 changes: 5 additions & 1 deletion examples/320 x 240/TFT_Matrix/TFT_Matrix.ino
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

// A fun MATRIX-like screen demo of scrolling
// Screen will flicker initially until fully drawn
// then scroll smoothly
Expand All @@ -15,13 +16,16 @@

#include <TFT_eSPI.h> // Hardware-specific library
#include <SPI.h>

#include "..\lib\TFT_eSPI\TFT_Drivers\ILI9341_Defines.h"
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library

#define TEXT_HEIGHT 8 // Height of text to be printed and scrolled
#define BOT_FIXED_AREA 0 // Number of lines in bottom fixed area (lines counted from bottom of screen)
#define TOP_FIXED_AREA 0 // Number of lines in top fixed area (lines counted from top of screen)

void setupScrollArea(uint16_t TFA, uint16_t BFA);
int scroll_slow(int lines, int wait);
void scrollAddress(uint16_t VSP);
uint16_t yStart = TOP_FIXED_AREA;
uint16_t yArea = 320 - TOP_FIXED_AREA - BOT_FIXED_AREA;
uint16_t yDraw = 320 - BOT_FIXED_AREA - TEXT_HEIGHT;
Expand Down
111 changes: 74 additions & 37 deletions examples/GUI Widgets/Buttons/Button_demo/Button_demo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
// https://github.com/Bodmer/TFT_eWidget

#include <FS.h>
#include "Free_Fonts.h" // Include the header file attached to this sketch
#include "..\lib\TFT_eSPI\examples\GUI Widgets\Buttons\Button_demo\Free_Fonts.h" // Include the header file attached to this sketch

#include <TFT_eSPI.h> // Hardware-specific library
#include <TFT_eWidget.h> // Widget library
#include "../lib/TFT_eSPI/TFT_eWidget/src/TFT_eWidget.h" // Widget library




TFT_eSPI tft = TFT_eSPI(); // Invoke custom library

Expand All @@ -25,6 +28,74 @@ ButtonWidget btnR = ButtonWidget(&tft);
ButtonWidget* btn[] = {&btnL , &btnR};;
uint8_t buttonCount = sizeof(btn) / sizeof(btn[0]);



// Declaraton of functions
void btnL_pressAction(void);
void btnL_releaseAction(void);
void btnR_pressAction(void);
void btnR_releaseAction(void);
void initButtons();
void touch_calibrate();









void setup() {
Serial.begin(115200);
tft.begin();
tft.setRotation(0);
tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18);

// Calibrate the touch screen and retrieve the scaling factors
touch_calibrate();
initButtons();
}

void loop() {
static uint32_t scanTime = millis();
uint16_t t_x = 9999, t_y = 9999; // To store the touch coordinates

// Scan keys every 50ms at most
if (millis() - scanTime >= 50) {
// Pressed will be set true if there is a valid touch on the screen
bool pressed = tft.getTouch(&t_x, &t_y);
scanTime = millis();
for (uint8_t b = 0; b < buttonCount; b++) {
if (pressed) {
if (btn[b]->contains(t_x, t_y)) {
btn[b]->press(true);
btn[b]->pressAction();
}
}
else {
btn[b]->press(false);
btn[b]->releaseAction();
}
}
}

}














void btnL_pressAction(void)
{
if (btnL.justPressed()) {
Expand Down Expand Up @@ -88,42 +159,7 @@ void initButtons() {
btnR.drawSmoothButton(false, 3, TFT_BLACK); // 3 is outline width, TFT_BLACK is the surrounding background colour for anti-aliasing
}

void setup() {
Serial.begin(115200);
tft.begin();
tft.setRotation(0);
tft.fillScreen(TFT_BLACK);
tft.setFreeFont(FF18);

// Calibrate the touch screen and retrieve the scaling factors
touch_calibrate();
initButtons();
}

void loop() {
static uint32_t scanTime = millis();
uint16_t t_x = 9999, t_y = 9999; // To store the touch coordinates

// Scan keys every 50ms at most
if (millis() - scanTime >= 50) {
// Pressed will be set true if there is a valid touch on the screen
bool pressed = tft.getTouch(&t_x, &t_y);
scanTime = millis();
for (uint8_t b = 0; b < buttonCount; b++) {
if (pressed) {
if (btn[b]->contains(t_x, t_y)) {
btn[b]->press(true);
btn[b]->pressAction();
}
}
else {
btn[b]->press(false);
btn[b]->releaseAction();
}
}
}

}

void touch_calibrate()
{
Expand Down Expand Up @@ -189,3 +225,4 @@ void touch_calibrate()
}
}
}

2 changes: 1 addition & 1 deletion examples/GUI Widgets/Graphs/Graph_demo_1/Graph_demo_1.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <TFT_eSPI.h>
TFT_eSPI tft = TFT_eSPI();

#include <TFT_eWidget.h> // Widget library
#include "../lib/TFT_eSPI/TFT_eWidget/src/TFT_eWidget.h" // Widget library

GraphWidget gr = GraphWidget(&tft); // Graph widget gr instance with pointer to tft
TraceWidget tr = TraceWidget(&gr); // Graph trace tr with pointer to gr
Expand Down
2 changes: 1 addition & 1 deletion examples/GUI Widgets/Graphs/Graph_demo_2/Graph_demo_2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <TFT_eSPI.h>
TFT_eSPI tft = TFT_eSPI();

#include <TFT_eWidget.h> // Widget library
#include "../lib/TFT_eSPI/TFT_eWidget/src/TFT_eWidget.h" // Widget library

GraphWidget gr = GraphWidget(&tft); // Graph widget

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

#include <TFT_eSPI.h> // Hardware-specific library
#include <TFT_eWidget.h> // Widget library
#include "../lib/TFT_eSPI/TFT_eWidget/src/TFT_eWidget.h"// Widget library

TFT_eSPI tft = TFT_eSPI(); // Invoke custom library

Expand Down
2 changes: 1 addition & 1 deletion examples/GUI Widgets/Sliders/Slider_demo/Slider_demo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "Free_Fonts.h" // Include the header file attached to this sketch

#include <TFT_eSPI.h>
#include <TFT_eWidget.h> // Widget library
#include "../lib/TFT_eSPI/TFT_eWidget/src/TFT_eWidget.h" // Widget library

TFT_eSPI tft = TFT_eSPI();
TFT_eSprite knob = TFT_eSprite(&tft); // Sprite for the slide knob
Expand Down