from ili934xnew import ILI9341, color565
from machine import Pin, SPI, ADC
from micropython import const
import time
import tt24
SCR_WIDTH = const(320)
SCR_HEIGHT = const(240)
SCR_ROT = const(1)
TFT_CLK_PIN = const(18)
TFT_MOSI_PIN = const(19)
TFT_CS_PIN = const(17)
TFT_RST_PIN = const(21) # your wiring: GP21
TFT_DC_PIN = const(20) # your wiring: GP20
# No MISO passed — Wokwi ILI9341 doesn't use it
spi = SPI(
0,
baudrate=10000000,
mosi=Pin(TFT_MOSI_PIN),
sck=Pin(TFT_CLK_PIN)
)
display = ILI9341(
spi,
cs=Pin(TFT_CS_PIN),
dc=Pin(TFT_DC_PIN),
rst=Pin(TFT_RST_PIN),
w=SCR_WIDTH,
h=SCR_HEIGHT,
r=SCR_ROT
)
display.set_font(tt24)
display.erase()
# Potentiometer on GP27 per your wiring
adc = ADC(Pin(27))
x_start = 30
x_end = 260
x_pos = x_start
y_base = 200
time_sec = 0
def draw_line(x0, y0, x1, y1, color):
dx = abs(x1 - x0)
dy = -abs(y1 - y0)
sx = 1 if x0 < x1 else -1
sy = 1 if y0 < y1 else -1
err = dx + dy
while True:
display.pixel(x0, y0, color)
if x0 == x1 and y0 == y1:
break
e2 = 2 * err
if e2 >= dy:
err += dy
x0 += sx
if e2 <= dx:
err += dx
y0 += sy
def draw_filled_circle(x0, y0, r, color):
for y in range(-r, r + 1):
for x in range(-r, r + 1):
if x * x + y * y <= r * r:
display.pixel(x0 + x, y0 + y, color)
def draw_axes():
draw_line(x_start, 40, x_start, y_base, color565(255, 255, 255))
draw_line(x_start, y_base, x_end, y_base, color565(255, 255, 255))
for t in range(20, 45, 5):
y = y_base - (t - 20) * 5
display.set_pos(5, y - 10) # (col, row) — matches PDF
display.print(str(t))
draw_axes()
while True:
adc_value = adc.read_u16()
voltage_mv = (adc_value / 65535.0) * 3300
temperature_c = voltage_mv / 10.0
display.set_color(color565(255, 255, 255), color565(0, 0, 0))
display.fill_rectangle(180, 10, 130, 70, color565(0, 0, 0))
display.set_pos(140, 10)
display.print("Napon: {:.0f}mV".format(voltage_mv))
display.set_pos(140, 35)
display.print("Temp: {:.1f}C".format(temperature_c))
display.set_pos(180, 60)
display.print("Vrijeme: {}s".format(time_sec))
y_temp = int(y_base - (temperature_c - 20) * 5)
if 20 <= temperature_c <= 40:
draw_filled_circle(x_pos, y_temp, 2, color565(255, 0, 0))
x_pos += 5
time_sec += 1
if x_pos > x_end:
display.erase()
draw_axes()
x_pos = x_start
time_sec = 0
time.sleep(1)