#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#define TFT_CS 10
#define TFT_RST 9
#define TFT_DC 8
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
const static uint8_t PROGMEM rotatingImage[] =
{ 56, 43,
B00000000, B00000000, B00000001, B11111111, B10000000, B00000000, B00000000,
B00000000, B00000000, B00001111, B11111111, B11110000, B00000000, B00000000,
B00000000, B00000000, B00011111, B11111111, B11111100, B00000000, B00000000,
B00000000, B00000000, B00111111, B11111111, B11111110, B00000000, B00000000,
B00000000, B00000000, B00111111, B11111111, B11111110, B00000000, B00000000,
B00000000, B00000000, B01111111, B11111111, B11111111, B00000000, B00000000,
B00000000, B00000000, B01111111, B11100111, B11111111, B00000000, B00000000,
B00000000, B00000000, B11111100, B00000000, B00111111, B00000000, B00000000,
B00000000, B00000000, B11111111, B00000000, B11111111, B10000000, B00000000,
B00000000, B00000001, B11111111, B11111111, B11111111, B11000000, B00000000,
B00000000, B00000011, B11111111, B11111111, B11111111, B11000000, B00000000,
B00000000, B00000111, B11110000, B00000000, B00001111, B11100000, B00000000,
B00000000, B00001111, B10000000, B00000000, B00000001, B11110000, B00000000,
B00000000, B00011110, B00000000, B00000000, B00000000, B01110000, B00000000,
B00000000, B01111100, B00000000, B00000000, B00000000, B00111110, B00000000,
B00000001, B11111000, B00000000, B00000000, B00000000, B00011111, B10000000,
B00000111, B11111000, B00000000, B00000000, B00000000, B00011111, B11100000,
B00011111, B11110000, B00000000, B00000000, B00000000, B00001111, B11111000,
B00111110, B00110000, B00000000, B00000000, B00000000, B00001100, B00111110,
B11100000, B00110000, B00000000, B00000000, B00000000, B00001100, B00000001,
B00000000, B00110000, B00000000, B00000000, B00000000, B00001100, B00000000,
B00000000, B00110000, B00000000, B00000000, B00000000, B00001100, B00000000,
B00000000, B00110000, B00000000, B00000000, B00000000, B00001100, B00000000,
B00000000, B00110000, B00000000, B00000000, B00000000, B00001100, B00000000,
B00000000, B00110000, B00000000, B00000000, B00000000, B00001100, B00000000,
B00000000, B00011000, B00000000, B00000000, B00000000, B00001100, B00000000,
B00000000, B00011000, B00000000, B00000000, B00000000, B00011000, B00000000,
B00000000, B00011000, B00000000, B00000000, B00000000, B00011000, B00000000,
B00000000, B00001100, B00000000, B00000000, B00000000, B00011000, B00000000,
B00000000, B00001100, B00000000, B00000000, B00000000, B00110000, B00000000,
B00000000, B00000110, B00000000, B00000000, B00000000, B00110000, B00000000,
B00000000, B00000111, B00000000, B00000000, B00000000, B01100000, B00000000,
B00000000, B00000011, B00000000, B00000000, B00000000, B01100000, B00000000,
B00000000, B00000001, B10000000, B00000000, B00000000, B11000000, B00000000,
B00000000, B00000000, B11000000, B00000000, B00000001, B10000000, B00000000,
B00000000, B00000000, B00100000, B00000000, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000,
B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111,
B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111,
B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111
};
void setup() {
Serial.begin(57600);
tft.initR(INITR_MINI160x80); // Init ST7735S mini display
// by default, we'll generate the high voltage from the 3.3v line
tft.setRotation(3); // Adjust the rotation based on your display orientation
tft.fillScreen(ST7735_BLACK);
}
void loop() {
for (int angle = 0; angle < 360; angle += 6) {
//tft.fillRect(40, 0, 80, 80, ST7735_BLACK); // Clear the display
drawRotatedBitmap(80, 40, rotatingImage, angle);
delay(10); // Pause so we see it
}
}
void drawRotatedBitmap(int16_t x, int16_t y, const uint8_t *bitmap, uint16_t angle) {
uint8_t w = pgm_read_byte(bitmap++);
uint8_t h = pgm_read_byte(bitmap++);
float cosa = cos(angle * 0.0174532925);
float sina = sin(angle * 0.0174532925);
// Calculate the center of rotation
float centerx = x + w / 2.0;
float centery = y + h / 2.0;
// Adjust the position based on your desired center
float targetx = tft.width() / 2.0; // Set to half of the screen width
float targety = tft.height() / 2.0; // Set to half of the screen height
for (int16_t j = 0; j < tft.height(); j++) { // Iterate over target area height
for (int16_t i = 0; i < tft.width(); i++) { // Iterate over target area width
// Calculate rotated coordinates around the adjusted center
float rotatedx = targetx + (i - targetx) * cosa - (j - targety) * sina;
float rotatedy = targety + (i - targetx) * sina + (j - targety) * cosa;
// Translate rotated coordinates back to source image space
float sx = (rotatedx - centerx) / cosa + centery / sina;
float sy = (rotatedy - centery) / sina - centerx / cosa;
// Check if pixel is within source image bounds
if (sx >= 0 && sx < w && sy >= 0 && sy < h) {
// Calculate corresponding pixel index in source image
int index = (int)sy * w + (int)sx;
// Extract pixel data from source image
uint8_t data = pgm_read_byte(bitmap + index / 8);
if (data & (1 << (7 - (index % 8)))) {
// Set pixel on the display
tft.drawPixel(i, j, ST7735_WHITE);
}
}
}
}
}