Last active
January 28, 2022 18:05
-
-
Save hollyhockberry/4ad5a171321ca849d0932603ec4341a2 to your computer and use it in GitHub Desktop.
M5Atom: LGFX: test for Waveshare 1.28inch Round LCD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define LGFX_USE_V1 | |
#include <SPIFFS.h> | |
#include <LovyanGFX.hpp> | |
constexpr static char PNG_FILE[] = "/picture.png"; | |
class LGFX : public lgfx::LGFX_Device { | |
lgfx::Panel_GC9A01 _panel_instance; | |
lgfx::Bus_SPI _bus_instance; | |
lgfx::Light_PWM _light_instance; | |
public: | |
LGFX() { | |
auto bus_cfg = _bus_instance.config(); | |
bus_cfg.spi_host = VSPI_HOST; | |
bus_cfg.spi_mode = 0; | |
bus_cfg.freq_write = 40000000; | |
bus_cfg.freq_read = 16000000; | |
bus_cfg.spi_3wire = true; | |
bus_cfg.use_lock = true; | |
bus_cfg.dma_channel = 1; | |
bus_cfg.pin_sclk = 33; | |
bus_cfg.pin_mosi = 23; | |
bus_cfg.pin_miso = -1; | |
bus_cfg.pin_dc = 19; | |
_bus_instance.config(bus_cfg); | |
_panel_instance.setBus(&_bus_instance); | |
auto panel_cfg = _panel_instance.config(); | |
panel_cfg.pin_cs = 22; | |
panel_cfg.pin_rst = 25; | |
panel_cfg.pin_busy = -1; | |
panel_cfg.memory_width = 240; | |
panel_cfg.memory_height = 240; | |
panel_cfg.panel_width = 240; | |
panel_cfg.panel_height = 240; | |
panel_cfg.offset_x = 0; | |
panel_cfg.offset_y = 0; | |
panel_cfg.offset_rotation = 0; | |
panel_cfg.dummy_read_pixel = 8; | |
panel_cfg.dummy_read_bits = 1; | |
panel_cfg.readable = false; | |
panel_cfg.invert = true; | |
panel_cfg.rgb_order = false; | |
panel_cfg.dlen_16bit = false; | |
panel_cfg.bus_shared = false; | |
_panel_instance.config(panel_cfg); | |
auto light_cfg = _light_instance.config(); | |
light_cfg.pin_bl = 21; | |
light_cfg.invert = false; | |
light_cfg.freq = 44100; | |
light_cfg.pwm_channel = 7; | |
_light_instance.config(light_cfg); | |
_panel_instance.setLight(&_light_instance); | |
setPanel(&_panel_instance); | |
} | |
} display; | |
LGFX_Sprite record(&display); | |
float angle; | |
void draw(float curr) { | |
if (curr == angle) { | |
return; | |
} | |
angle = curr; | |
display.startWrite(); | |
record.pushRotateZoom( | |
record.width() / 2, record.height() / 2, angle, 1.f, 1.f, TFT_BLACK); | |
display.endWrite(); | |
display.waitDisplay(); | |
} | |
float readFader() { | |
return static_cast<float>(map(::analogRead(32), 0, 4096, 0, 3600) / 10.f); | |
} | |
void setup() { | |
SPIFFS.begin(); | |
display.init(); | |
record.createSprite(240, 240); | |
record.drawPngFile(SPIFFS, PNG_FILE, 0, 0); | |
angle = -1.f; | |
} | |
void loop() { | |
::draw(::readFader()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment