# Import necessary modules
from machine import SPI, Pin
from MicroPython-ST7735 import TFT
import time
import math
# Define pin numbers
BL = 13
DC = 8
RST = 12
MOSI = 11
SCK = 10
CS = 9
# Initialize SPI communication
spi = SPI(1, baudrate=20000000, polarity=0, phase=0, sck=Pin(SCK), mosi=Pin(MOSI), miso=None)
# Initialize the ST7735 display
tft = TFT(spi, DC, RST, CS)
tft.initr()
tft.rgb(True) # Enable color
# Function to draw rotated lines for testing
def testlines(color):
tft.fill(TFT.BLACK)
for x in range(0, tft.size(), 6):
tft.line((0, 0), (x, tft.size() - 1), color)
# Repeat for other quadrants (adjust coordinates accordingly)
# Rotate the image by changing the angle
def rotate_image(image, angle):
# Convert angle to radians
rad_angle = math.radians(angle)
# Calculate new coordinates after rotation
new_x = 80 + int(math.cos(rad_angle) * 80)
new_y = 40 + int(math.sin(rad_angle) * 40)
# Draw the rotated image (replace with your actual image drawing logic)
tft.pixel(new_x, new_y, TFT.WHITE) # Example: Draw a single pixel
# Load your image data (replace with your actual image)
rotating_image = b'\x00\x00\x00\x00\x00\x00\x00\x00' # Example data
# Main loop
while True:
for angle in range(0, 360, 6):
tft.fill(TFT.BLACK) # Clear the display
rotate_image(rotating_image, angle)
time.sleep_ms(10) # Pause to see the rotation