#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SPI.h>
#define TFT_CS 10
#define TFT_RST 9
#define TFT_DC 8
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
int munecoX = 20;
int munecoY = 120;
int munecoWidth = 20;
int munecoHeight = 40;
void setup() {
Serial.begin(9600);
tft.begin();
tft.setRotation(3); // Ajusta la orientación de la pantalla si es necesario
tft.fillScreen(ILI9341_BLACK); // Llena la pantalla de negro al iniciar
walkAnimation(); // Inicia la animación del muñeco
}
void loop() {
// El loop puede estar vacío si todo el trabajo se hace en la función de animación
}
void drawCharacter(int x, int y, uint16_t color) {
// Dibuja el cuerpo del muñeco
tft.fillRect(x, y, munecoWidth, munecoHeight, color);
// Dibuja la cabeza
tft.fillCircle(x + munecoWidth / 2, y - 10, 10, ILI9341_WHITE);
// Dibuja los brazos
int armsLength = 20;
tft.drawLine(x, y + munecoHeight / 2, x - armsLength, y + munecoHeight / 2 - armsLength, ILI9341_WHITE);
tft.drawLine(x + munecoWidth, y + munecoHeight / 2, x + munecoWidth + armsLength, y + munecoHeight / 2 - armsLength, ILI9341_WHITE);
// Dibuja las piernas
int legsLength = 30;
tft.drawLine(x + munecoWidth / 2, y + munecoHeight, x + munecoWidth / 2 + legsLength, y + munecoHeight + legsLength, ILI9341_WHITE);
tft.drawLine(x + munecoWidth / 2, y + munecoHeight, x + munecoWidth / 2 - legsLength, y + munecoHeight + legsLength, ILI9341_WHITE);
}
void walkAnimation() {
for (int i = 0; i < 3; i++) {
delay(500); // Retraso para simular movimiento
drawCharacter(munecoX, munecoY, ILI9341_RED); // Dibuja el muñeco en la nueva posición en rojo
delay(500); // Retraso para simular movimiento
drawCharacter(munecoX, munecoY, ILI9341_BLACK); // Borra el muñeco actual
munecoX += 5; // Mueve el muñeco horizontalmente
}
}