#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <Servo.h>
// --- Screen Pins ---
#define TFT_CS 17
#define TFT_DC 16
#define TFT_MOSI 19
#define TFT_SCK 18
#define TFT_RST 15
// Initialize using SOFTWARE SPI to prevent simulator freezing (100% speed)
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCK, TFT_RST);
// --- Servo Pins ---
#define LEFT_MOTOR_PIN 0
#define RIGHT_MOTOR_PIN 1
Servo leftMotor;
Servo rightMotor;
void setup() {
// Start the screen
tft.begin();
tft.setRotation(1); // Set to landscape mode
// Draw the Robot Face
drawFace();
// Start the servos
leftMotor.attach(LEFT_MOTOR_PIN);
rightMotor.attach(RIGHT_MOTOR_PIN);
}
void loop() {
// Move Forward
leftMotor.write(180);
rightMotor.write(0);
delay(2000);
// Stop
leftMotor.write(90);
rightMotor.write(90);
delay(1000);
// Move Backward
leftMotor.write(0);
rightMotor.write(180);
delay(2000);
// Stop
leftMotor.write(90);
rightMotor.write(90);
delay(1000);
}
// Function to draw the face on the ILI9341
void drawFace() {
tft.fillScreen(ILI9341_BLACK); // Dark background
// Left Eye (Cyan)
tft.fillCircle(100, 100, 35, ILI9341_CYAN);
// Right Eye (Cyan)
tft.fillCircle(220, 100, 35, ILI9341_CYAN);
// Mouth (Yellow rounded rectangle)
tft.fillRoundRect(90, 170, 140, 20, 10, ILI9341_YELLOW);
// Cute little "ROBO" text at the top
tft.setCursor(120, 20);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(3);
tft.print("ROBO");
}