Comments (12)
Here is the code i used
/*
Arduino Watch Lite Version
You may find full version at: https://github.com/moononournation/ArduinoWatch
*/
/*******************************************************************************
- Start of Arduino_GFX setting
******************************************************************************/
#include "Arduino_HWSPI.h"
//#include "Arduino_ESP32SPI.h"
//#include "Arduino_SWSPI.h"
#include "Arduino_GFX.h" // Core graphics library
#include "Arduino_Display.h" // Various display driver
#define TFT_CS 15
#define TFT_DC 2
#define TFT_RST 4
#define TFT_BL 32
/*
- Step 1: Initize one databus for your display
*/
// General software SPI
// Arduino_DataBus bus = new Arduino_SWSPI(TFT_DC, TFT_CS, 18 / SCK /, 23 / MOSI /, -1 / MISO */);
// General hardware SPI
Arduino_DataBus *bus = new Arduino_HWSPI(TFT_DC, TFT_CS);
// ESP32 hardware SPI, more customizable parameters
// Arduino_DataBus bus = new Arduino_ESP32SPI(TFT_DC, TFT_CS, 18 / SCK /, 23 / MOSI /, -1 / MISO /, VSPI / spi_num */);
/*
- Step 2: Initize one driver for your display
*/
// Canvas (framebuffer)
// Arduino_ST7789 output_display = new Arduino_ST7789(bus, TFT_RST, 0 / rotation /, true / IPS */);
// 16-bit color Canvas (240x320 resolution only works for ESP32 with PSRAM)
// Arduino_Canvas gfx = new Arduino_Canvas(240 / width /, 320 / height */, output_display);
// Indexed color Canvas, mask_level: 0-2, larger mask level mean less color variation but can have faster index mapping
// Arduino_Canvas_Indexed gfx = new Arduino_Canvas_Indexed(240 / width /, 320 / height /, output_display, 0 / output_x /, 0 / output_y /, MAXMASKLEVEL / mask_level */);
// GC9A01 IPS LCD 240x240
Arduino_GC9A01 gfx = new Arduino_GC9A01(bus, TFT_RST, 0 / rotation /, true / IPS */);
// HX8347C IPS LCD 240x320
// Arduino_HX8347C gfx = new Arduino_HX8347C(bus, TFT_RST, 0 / rotation /, true / IPS */);
// HX8352C IPS LCD 240x400
// Arduino_HX8352C gfx = new Arduino_HX8352C(bus, TFT_RST, 0 / rotation /, true / IPS */);
// HX8357B IPS LCD 320x480
// Arduino_HX8357B gfx = new Arduino_HX8357B(bus, TFT_RST, 0 / rotation /, true / IPS */);
// ILI9225 LCD 176x220
// Arduino_ILI9225 *gfx = new Arduino_ILI9225(bus, TFT_RST);
// ILI9341 LCD 240x320
//Arduino_ILI9341 *gfx = new Arduino_ILI9341(bus, TFT_RST);
// ILI9481 LCD 320x480
// Arduino_ILI9481_18bit *gfx = new Arduino_ILI9481_18bit(bus, TFT_RST);
// ILI9486 LCD 320x480
// Arduino_ILI9486_18bit *gfx = new Arduino_ILI9486_18bit(bus, TFT_RST);
// SEPS525 OLED 160x128
// Arduino_SEPS525 *gfx = new Arduino_SEPS525(bus, TFT_RST);
// SSD1283A OLED 130x130
// Arduino_SSD1283A *gfx = new Arduino_SSD1283A(bus, TFT_RST);
// SSD1331 OLED 96x64
// Arduino_SSD1331 *gfx = new Arduino_SSD1331(bus, TFT_RST);
// SSD1351 OLED 128x128
// Arduino_SSD1351 *gfx = new Arduino_SSD1351(bus, TFT_RST);
// ST7735 LCD
// 1.8" REDTAB 128x160
// Arduino_ST7735 *gfx = new Arduino_ST7735(bus, TFT_RST);
// 1.8" BLACKTAB 128x160
// Arduino_ST7735 gfx = new Arduino_ST7735(bus, TFT_RST, 0 / rotation /, false / IPS /, 128 / width /, 160 / height /, 2 / col offset 1 /, 1 / row offset 1 /, 2 / col offset 2 /, 1 / row offset 2 /, false / BGR */);
// 1.8" GREENTAB A 128x160
// Arduino_ST7735 gfx = new Arduino_ST7735(bus, TFT_RST, 0 / rotation /, false / IPS /, 128 / width /, 160 / height /, 2 / col offset 1 /, 1 / row offset 1 /, 2 / col offset 2 /, 1 / row offset 2 */);
// 1.8" GREENTAB B 128x160
// Arduino_ST7735 gfx = new Arduino_ST7735(bus, TFT_RST, 0 / rotation /, false / IPS /, 128 / width /, 160 / height /, 2 / col offset 1 /, 3 / row offset 1 /, 2 / col offset 2 /, 1 / row offset 2 */);
// 1.8" Wide angle LCD 128x160
// Arduino_ST7735 gfx = new Arduino_ST7735(bus, TFT_RST, 2 / rotation /, false / IPS /, 128 / width /, 160 / height /, 0 / col offset 1 /, 0 / row offset 1 /, 0 / col offset 2 /, 0 / row offset 2 /, false / BGR */);
// 1.5" GREENTAB B 128x128
// Arduino_ST7735 gfx = new Arduino_ST7735(bus, TFT_RST, 0 / rotation /, false / IPS /, 128 / width /, 128 / height /, 2 / col offset 1 /, 3 / row offset 1 /, 2 / col offset 2 /, 1 / row offset 2 */);
// 1.5" GREENTAB C 128x128
// Arduino_ST7735 gfx = new Arduino_ST7735(bus, TFT_RST, 0 / rotation /, false / IPS /, 128 / width /, 128 / height /, 0 / col offset 1 /, 32 / row offset 1 */);
// 0.96" IPS LCD 80x160
// Arduino_ST7735 gfx = new Arduino_ST7735(bus, TFT_RST, 3 / rotation /, true / IPS /, 80 / width /, 160 / height /, 26 / col offset 1 /, 1 / row offset 1 /, 26 / col offset 2 /, 1 / row offset 2 */);
// ST7789 LCD
// 2.4" LCD 240x320
// Arduino_ST7789 *gfx = new Arduino_ST7789(bus, TFT_RST);
// 2.4" IPS LCD 240x320
// Arduino_ST7789 gfx = new Arduino_ST7789(bus, TFT_RST, 0 / rotation /, true / IPS */);
// 1.3"/1.5" square IPS LCD 240x240
// Arduino_ST7789 gfx = new Arduino_ST7789(bus, TFT_RST, 2 / rotation /, true / IPS /, 240 / width /, 240 / height /, 0 / col offset 1 /, 80 / row offset 1 */);
// 1.14" IPS LCD 135x240 TTGO T-Display
// Arduino_ST7789 gfx = new Arduino_ST7789(bus, TFT_RST, 0 / rotation /, true / IPS /, 135 / width /, 240 / height /, 53 / col offset 1 /, 40 / row offset 1 /, 52 / col offset 2 /, 40 / row offset 2 */);
// ST7796 LCD
// 4" LCD 320x480
// Arduino_ST7796 *gfx = new Arduino_ST7796(bus, TFT_RST);
// 4" IPS LCD 320x480
// Arduino_ST7796 gfx = new Arduino_ST7796(bus, TFT_RST, 0 / rotation /, true / IPS */);
#endif /* not a specific hardware /
/******************************************************************************
- End of Arduino_GFX setting
******************************************************************************/
#define BACKGROUND BLACK
#define MARK_COLOR WHITE
#define SUBMARK_COLOR DARKGREY // LIGHTGREY
#define HOUR_COLOR WHITE
#define MINUTE_COLOR BLUE // LIGHTGREY
#define SECOND_COLOR RED
#define SIXTIETH 0.016666667
#define TWELFTH 0.08333333
#define SIXTIETH_RADIAN 0.10471976
#define TWELFTH_RADIAN 0.52359878
#define RIGHT_ANGLE_RADIAN 1.5707963
static uint8_t conv2d(const char *p)
{
uint8_t v = 0;
return (10 * (p - '0')) + (++p - '0');
}
static int16_t w, h, center;
static int16_t hHandLen, mHandLen, sHandLen, markLen;
static float sdeg, mdeg, hdeg;
static int16_t osx = 0, osy = 0, omx = 0, omy = 0, ohx = 0, ohy = 0; // Saved H, M, S x & y coords
static int16_t nsx, nsy, nmx, nmy, nhx, nhy; // H, M, S x & y coords
static int16_t xMin, yMin, xMax, yMax; // redraw range
static int16_t hh, mm, ss;
static unsigned long targetTime; // next action time
static int16_t *cached_points;
static int cached_points_idx = 0;
static int16_t *last_cached_point;
void setup(void)
{
gfx->begin();
gfx->fillScreen(BACKGROUND);
#ifdef TFT_BL
pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, HIGH);
#endif
// init LCD constant
w = gfx->width();
h = gfx->height();
if (w < h)
{
center = w / 2;
}
else
{
center = h / 2;
}
hHandLen = center * 3 / 8;
mHandLen = center * 2 / 3;
sHandLen = center * 5 / 6;
markLen = sHandLen / 6;
cached_points = (int16_t *)malloc((hHandLen + 1 + mHandLen + 1 + sHandLen + 1) * 2 * 2);
// Draw 60 clock marks
draw_round_clock_mark(
// draw_square_clock_mark(
center - markLen, center,
center - (markLen * 2 / 3), center,
center - (markLen / 2), center);
hh = conv2d(__TIME__);
mm = conv2d(__TIME__ + 3);
ss = conv2d(__TIME__ + 6);
targetTime = ((millis() / 1000) + 1) * 1000;
}
void loop()
{
unsigned long cur_millis = millis();
if (cur_millis >= targetTime)
{
targetTime += 1000;
ss++; // Advance second
if (ss == 60)
{
ss = 0;
mm++; // Advance minute
if (mm > 59)
{
mm = 0;
hh++; // Advance hour
if (hh > 23)
{
hh = 0;
}
}
}
}
// Pre-compute hand degrees, x & y coords for a fast screen update
sdeg = SIXTIETH_RADIAN * ((0.001 * (cur_millis % 1000)) + ss); // 0-59 (includes millis)
nsx = cos(sdeg - RIGHT_ANGLE_RADIAN) * sHandLen + center;
nsy = sin(sdeg - RIGHT_ANGLE_RADIAN) * sHandLen + center;
if ((nsx != osx) || (nsy != osy))
{
mdeg = (SIXTIETH * sdeg) + (SIXTIETH_RADIAN * mm); // 0-59 (includes seconds)
hdeg = (TWELFTH * mdeg) + (TWELFTH_RADIAN * hh); // 0-11 (includes minutes)
mdeg -= RIGHT_ANGLE_RADIAN;
hdeg -= RIGHT_ANGLE_RADIAN;
nmx = cos(mdeg) * mHandLen + center;
nmy = sin(mdeg) * mHandLen + center;
nhx = cos(hdeg) * hHandLen + center;
nhy = sin(hdeg) * hHandLen + center;
// redraw hands
redraw_hands_cached_draw_and_erase();
ohx = nhx;
ohy = nhy;
omx = nmx;
omy = nmy;
osx = nsx;
osy = nsy;
delay(1);
}
}
void draw_round_clock_mark(int16_t innerR1, int16_t outerR1, int16_t innerR2, int16_t outerR2, int16_t innerR3, int16_t outerR3)
{
float x, y;
int16_t x0, x1, y0, y1, innerR, outerR;
uint16_t c;
for (int i = 0; i < 60; i++)
{
if ((i % 15) == 0)
{
innerR = innerR1;
outerR = outerR1;
c = MARK_COLOR;
}
else if ((i % 5) == 0)
{
innerR = innerR2;
outerR = outerR2;
c = MARK_COLOR;
}
else
{
innerR = innerR3;
outerR = outerR3;
c = SUBMARK_COLOR;
}
mdeg = (SIXTIETH_RADIAN * i) - RIGHT_ANGLE_RADIAN;
x = cos(mdeg);
y = sin(mdeg);
x0 = x * outerR + center;
y0 = y * outerR + center;
x1 = x * innerR + center;
y1 = y * innerR + center;
gfx->drawLine(x0, y0, x1, y1, c);
}
}
void draw_square_clock_mark(int16_t innerR1, int16_t outerR1, int16_t innerR2, int16_t outerR2, int16_t innerR3, int16_t outerR3)
{
float x, y;
int16_t x0, x1, y0, y1, innerR, outerR;
uint16_t c;
for (int i = 0; i < 60; i++)
{
if ((i % 15) == 0)
{
innerR = innerR1;
outerR = outerR1;
c = MARK_COLOR;
}
else if ((i % 5) == 0)
{
innerR = innerR2;
outerR = outerR2;
c = MARK_COLOR;
}
else
{
innerR = innerR3;
outerR = outerR3;
c = SUBMARK_COLOR;
}
if ((i >= 53) || (i < 8))
{
x = tan(SIXTIETH_RADIAN * i);
x0 = center + (x * outerR);
y0 = center + (1 - outerR);
x1 = center + (x * innerR);
y1 = center + (1 - innerR);
}
else if (i < 23)
{
y = tan((SIXTIETH_RADIAN * i) - RIGHT_ANGLE_RADIAN);
x0 = center + (outerR);
y0 = center + (y * outerR);
x1 = center + (innerR);
y1 = center + (y * innerR);
}
else if (i < 38)
{
x = tan(SIXTIETH_RADIAN * i);
x0 = center - (x * outerR);
y0 = center + (outerR);
x1 = center - (x * innerR);
y1 = center + (innerR);
}
else if (i < 53)
{
y = tan((SIXTIETH_RADIAN * i) - RIGHT_ANGLE_RADIAN);
x0 = center + (1 - outerR);
y0 = center - (y * outerR);
x1 = center + (1 - innerR);
y1 = center - (y * innerR);
}
gfx->drawLine(x0, y0, x1, y1, c);
}
}
void redraw_hands_cached_draw_and_erase()
{
gfx->startWrite();
draw_and_erase_cached_line(center, center, nsx, nsy, SECOND_COLOR, cached_points, sHandLen + 1, false, false);
draw_and_erase_cached_line(center, center, nhx, nhy, HOUR_COLOR, cached_points + ((sHandLen + 1) * 2), hHandLen + 1, true, false);
draw_and_erase_cached_line(center, center, nmx, nmy, MINUTE_COLOR, cached_points + ((sHandLen + 1 + hHandLen + 1) * 2), mHandLen + 1, true, true);
gfx->endWrite();
}
void draw_and_erase_cached_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t color, int16_t *cache, int16_t cache_len, bool cross_check_second, bool cross_check_hour)
{
#if defined(ESP8266)
yield();
#endif
bool steep = _diff(y1, y0) > _diff(x1, x0);
if (steep)
{
_swap_int16_t(x0, y0);
_swap_int16_t(x1, y1);
}
int16_t dx, dy;
dx = _diff(x1, x0);
dy = _diff(y1, y0);
int16_t err = dx / 2;
int8_t xstep = (x0 < x1) ? 1 : -1;
int8_t ystep = (y0 < y1) ? 1 : -1;
x1 += xstep;
int16_t x, y, ox, oy;
for (uint16_t i = 0; i <= dx; i++)
{
if (steep)
{
x = y0;
y = x0;
}
else
{
x = x0;
y = y0;
}
ox = *(cache + (i * 2));
oy = *(cache + (i * 2) + 1);
if ((x == ox) && (y == oy))
{
if (cross_check_second || cross_check_hour)
{
write_cache_pixel(x, y, color, cross_check_second, cross_check_hour);
}
}
else
{
write_cache_pixel(x, y, color, cross_check_second, cross_check_hour);
if ((ox > 0) || (oy > 0))
{
write_cache_pixel(ox, oy, BACKGROUND, cross_check_second, cross_check_hour);
}
*(cache + (i * 2)) = x;
*(cache + (i * 2) + 1) = y;
}
if (err < dy)
{
y0 += ystep;
err += dx;
}
err -= dy;
x0 += xstep;
}
for (uint16_t i = dx + 1; i < cache_len; i++)
{
ox = *(cache + (i * 2));
oy = *(cache + (i * 2) + 1);
if ((ox > 0) || (oy > 0))
{
write_cache_pixel(ox, oy, BACKGROUND, cross_check_second, cross_check_hour);
}
*(cache + (i * 2)) = 0;
*(cache + (i * 2) + 1) = 0;
}
}
void write_cache_pixel(int16_t x, int16_t y, int16_t color, bool cross_check_second, bool cross_check_hour)
{
int16_t *cache = cached_points;
if (cross_check_second)
{
for (int i = 0; i <= sHandLen; i++)
{
if ((x == *(cache++)) && (y == *(cache)))
{
return;
}
cache++;
}
}
if (cross_check_hour)
{
cache = cached_points + ((sHandLen + 1) * 2);
for (int i = 0; i <= hHandLen; i++)
{
if ((x == *(cache++)) && (y == *(cache)))
{
return;
}
cache++;
}
}
gfx->writePixel(x, y, color);
}
from arduino_gfx.
I'm running on an ESP32 btw. Just like your youtube video, similar wiring but not the exact same
from arduino_gfx.
multiple libraries were found for "Arduino_HWSPI.h" means you have 2 or more versions of Arduino_GFX library folders, please remove all of them and download latest one again.
from arduino_gfx.
@moononournation does the latest one still reference unity.h?
I found this import can be removed, as I had the same error:
'''
C:\Users\nicol\OneDrive\Documents\Arduino\libraries\Arduino_GFX-master\Arduino_ESP32SPI_DMA.h:19:19: fatal error: unity.h: No such file or directory
'''
from arduino_gfx.
unity.h was added to arduino-esp32 on 27 Nov 2018: espressif/arduino-esp32#2108
Please update the arduino-esp32, some forum discussed how to do that: https://esp32.com/viewtopic.php?t=8284
from arduino_gfx.
I only have one arduino_gfx and I also have the latest version of esp32... (1.0.4)
Could it be interfering with another library?
from arduino_gfx.
I do get the same error on platformio and using only arduino_gfx library, so it cant interfer with anything else...
from arduino_gfx.
I have tried compile your code in above post with Arduino IDE 1.8.13, latest Arduino-esp32 and Arduino-GFX master branch. Every things goes well if I commented out #endif at line 115.
Sketch uses 234111 bytes (17%) of program storage space. Maximum is 1310720 bytes.
Global variables use 13596 bytes (4%) of dynamic memory, leaving 314084 bytes for local variables. Maximum is 327680 bytes.
from arduino_gfx.
So I just followed uvwxy advice, which was to comment out the #include "unity.h" and it fixed my problem... which isnt a real solution but that will be enought for me... (I had every latest versions of everything) so thats weird
from arduino_gfx.
I think you should locate why the compiler cannot find "unity.h" that should included in arduino-esp32. Or you will encounter further wired problems while development.
from arduino_gfx.
@moononournation I think you are absolutely right.
I still have one question: for what is the unity.h
needed in Arduino_ESP32SPI_DMA.h
?
I know removing it might not be the correct approach. But it still worked. Question is: why?
from arduino_gfx.
unity.h should only be used while unit test. But now I know it have a side effect that can prevent you using arduino-esp32 before 27 Nov 2018 ;P
from arduino_gfx.
Related Issues (20)
- General Question: Clipping HOT 1
- 16 bit i8080 interface ESP32s3+st7796 code,doesn't display anything HOT 5
- Code convertion from other lib HOT 2
- RP2040 1.28 WAVESHARE TOUCH LCD HOT 5
- Compilation error for BW16-kit HOT 10
- Waveshare display 3.5inches HOT 10
- Waveshare display 3.5inches #455
- #include <Arduino_GFX_Library.h> throws Error HOT 1
- Memory free about SpriteGif example HOT 2
- LVGL v9.1
- "MSB_16" redefined HOT 3
- No RM690B0 display driver for Lilygo T4-S3 (ESP32 Amoled Touch) HOT 3
- ESP32-4848S040C HOT 3
- When I use GC9107, colors are inverted. HOT 2
- Support for LilyGo T-Display S3 Long? HOT 4
- JC8048W550 ST7262 no display with V1.4.6 HOT 8
- Add support for TZT 1.9 Inch IPS 170x320 ST7789
- No image display from flash or SD (esp32S3-8048S070) HOT 7
- ILI9488 with Arduino UNO R3 HOT 7
- vscode+platformio ESP32S3 error HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduino_gfx.