Created
October 7, 2023 01:30
-
-
Save ESPboy-edu/f57c7d3dda8680aff5fe4e99380cd9c6 to your computer and use it in GitHub Desktop.
ESPboy/LovyanGFX pushImageRotateZoom() possible palette issue
This file contains 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_ESPBOY | |
#include <LovyanGFX.hpp> | |
#include <LGFX_AUTODETECT.hpp> | |
#include <Arduino.h> | |
#include <ESP8266WiFi.h> //WiFi controll | |
#include <Adafruit_NeoPixel.h> //RGB LED | |
#include <Adafruit_MCP23017.h> //GPIO extender (buttons and more) | |
#include <FS.h> | |
using fs::FS; | |
#define MCP23017address 0 // actually it's 0x20 but in <Adafruit_MCP23017.h> lib there is (x|0x20) :) | |
#define MCP4725address 0x60 | |
#define LEDPIN D4 | |
#define SOUNDPIN D3 | |
#define LEDLOCK 9 | |
#define CSTFTPIN 8 | |
#define PAD_LEFT 0x01 | |
#define PAD_UP 0x02 | |
#define PAD_DOWN 0x04 | |
#define PAD_RIGHT 0x08 | |
#define PAD_ACT 0x10 | |
#define PAD_ESC 0x20 | |
#define PAD_LFT 0x40 | |
#define PAD_RGT 0x80 | |
#define PAD_ANY 0xff | |
Adafruit_MCP23017 mcp; | |
Adafruit_NeoPixel led(1, LEDPIN, NEO_GRB + NEO_KHZ800); | |
//init gfx | |
static LGFX tft; | |
static LGFX_Sprite frameBuffer (&tft); | |
LGFX_Sprite spaceShip; | |
enum PAL{ | |
PICO8 = 0, | |
CGA, | |
MONO, | |
ZX, | |
C64, | |
WIN, | |
VIC20, | |
MACII, | |
MSX | |
}; | |
//--------------PALETTE-------------- | |
lgfx::rgb888_t const constexpr PALETTE [9][16] PROGMEM = { | |
{0x000000, 0x1D2B53, 0x7E2553, 0x008751, 0xAB5236, 0x5F574F, 0xC2C3C7, 0xFFF1E8, 0xFF004D, 0xFFA300, 0xFFEC27, 0x00E436, 0x29ADFF, 0x83769C, 0xFF77A8, 0xFFCCAA}, | |
{0x000000, 0xFFFFFF, 0xff00ff, 0x00FFFF, 0xFFFF00, 0x00FF00, 0x0000FF, 0xFF0000, 0x3F3F3F, 0x7F7F7F, 0x7F007F, 0x007F7F, 0x7F3F00, 0x007F00, 0x00007F, 0x7F0000}, | |
{0xFFFFFF, 0xAAAAAA, 0x555555, 0x000000, 0xFFEAED, 0xA1CEE8, 0x0092B6, 0x66005F, 0xEDFFEA, 0xFFB1E2, 0xB60092, 0x5F6600, 0xFFFFFF, 0xAAAAAA, 0x555555, 0x000000}, | |
{0x000000, 0x1C1C1C, 0x0000C0, 0x0000FF, 0xC00000, 0xFF0000, 0xC000C0, 0xFF00FF, 0x00C000, 0x00FF00, 0x00C0C0, 0x00FFFF, 0xC0C000, 0xFFFF00, 0xC0C0C0, 0xFFFFFF}, | |
{0x000000, 0x626262, 0x898989, 0xadadad, 0xffffff, 0x9f4e44, 0xcb7e75, 0x6d5412, 0xa1683c, 0xc9d487, 0x9ae29b, 0x5cab5e, 0x6abfc6, 0x887ecb, 0x50459b, 0xa057a3}, | |
{0x000000, 0x7e7e7e, 0xbebebe, 0xffffff, 0x7e0000, 0xfe0000, 0x047e00, 0x06ff04, 0x7e7e00, 0xffff04, 0x00007e, 0x0000ff, 0x7e007e, 0xfe00ff, 0x047e7e, 0x06ffff}, | |
{0x000000, 0xffffff, 0xa8734a, 0xe9b287, 0x772d26, 0xb66862, 0x85d4dc, 0xc5ffff, 0xa85fb4, 0xe99df5, 0x559e4a, 0x92df87, 0x42348b, 0x7e70ca, 0xbdcc71, 0xffffb0}, | |
{0xffffff, 0xffff00, 0xff6500, 0xdc0000, 0xff0097, 0x360097, 0x0000ca, 0x0097ff, 0x00a800, 0x006500, 0x653600, 0x976536, 0xb9b9b9, 0x868686, 0x454545, 0x000000}, | |
{0x000000, 0x191028, 0x46af45, 0xa1d685, 0x453e78, 0x7664fe, 0x833129, 0x9ec2e8, 0xdc534b, 0xe18d79, 0xd6b97b, 0xe9d8a1, 0x216c4b, 0xd365c8, 0xafaab9, 0xf5f4eb}, | |
}; | |
//--------------SPRITE-------------- | |
PROGMEM const uint8_t spriteSpaceShip[] = { | |
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x11, 0x10, 0x00, 0x00, 0x00, | |
0x00, 0x00, 0x00, 0x11, 0x10, 0x00, 0x00, 0x00, | |
0x00, 0x02, 0x00, 0x11, 0x10, 0x02, 0x00, 0x00, | |
0x00, 0x02, 0x00, 0x11, 0x10, 0x02, 0x00, 0x00, | |
0x00, 0x01, 0x01, 0x11, 0x11, 0x01, 0x00, 0x00, | |
0x20, 0x01, 0x31, 0x12, 0x11, 0x31, 0x00, 0x20, | |
0x20, 0x03, 0x11, 0x22, 0x21, 0x13, 0x00, 0x20, | |
0x10, 0x01, 0x11, 0x21, 0x21, 0x11, 0x00, 0x10, | |
0x10, 0x11, 0x11, 0x11, 0x11, 0x11, 0x10, 0x10, | |
0x11, 0x11, 0x12, 0x11, 0x12, 0x11, 0x11, 0x10, | |
0x11, 0x10, 0x22, 0x11, 0x12, 0x20, 0x11, 0x10, | |
0x11, 0x00, 0x22, 0x01, 0x02, 0x20, 0x01, 0x10, | |
0x10, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10 | |
}; | |
uint8_t ESPboyGetKeys() { return (~mcp.readGPIOAB() & 255); } | |
void setup(){ | |
Serial.begin(115200); | |
WiFi.mode(WIFI_OFF); // to safe battery power | |
//mcp23017 init | |
mcp.begin(MCP23017address); | |
//buttons init | |
for (int i=0;i<8;i++){ | |
mcp.pinMode(i, INPUT); | |
mcp.pullUp(i, HIGH);} | |
//LED init | |
pinMode(LEDPIN, OUTPUT); | |
mcp.pinMode(LEDLOCK, OUTPUT); | |
mcp.digitalWrite(LEDLOCK, HIGH); | |
led.begin(); | |
led.clear(); | |
led.show(); | |
led.show(); //i do not know why but first packet sent to LED AP106 does not work ) | |
digitalWrite(LEDPIN, HIGH); | |
//sound init | |
pinMode(SOUNDPIN, OUTPUT); | |
//display init | |
tft.init(); | |
tft.setRotation(0); | |
tft.fillScreen(0); | |
//set 4 bit colors (16 different colors palette) | |
frameBuffer.setColorDepth(4); | |
frameBuffer.createSprite(128, 128); | |
frameBuffer.clear(); | |
//set palette | |
for(int i=0; i<16; i++) | |
frameBuffer.setPaletteColor(i, (lgfx::rgb888_t)pgm_read_dword(&PALETTE[PAL::PICO8][i])); | |
} | |
void loop(){ | |
static uint8_t xset = 60; | |
static uint8_t yset = 60; | |
if (ESPboyGetKeys()&PAD_UP) yset--; | |
if (ESPboyGetKeys()&PAD_DOWN) yset++; | |
if (ESPboyGetKeys()&PAD_LEFT) xset--; | |
if (ESPboyGetKeys()&PAD_RIGHT) xset++; | |
if (ESPboyGetKeys()&PAD_ACT) {xset=60; yset=60;} | |
frameBuffer.clear(); | |
frameBuffer.pushImageRotateZoom(xset, yset, 0, 0, 0, 1, 1, 16, 16, spriteSpaceShip, 0, lgfx::color_depth_t::palette_4bit, &PALETTE[PAL::C64][0]); | |
frameBuffer.pushSprite(0, 0); | |
delay(1); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment