import machine
import ssd1306
import framebuf
from time import sleep
def scroll_screen_in_out(screen):
for i in range (0, (oled_width+1)*2, 2):
for line in screen:
oled.text(line[2], -oled_width+i, line[1])
oled.show()
if i!= oled_width:
oled.fill(0)
# ESP32 Pin assignment
i2c = machine.SoftI2C(scl=machine.Pin(22), sda=machine.Pin(21))
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
def display_pump_status(oled, pump_on):
water_drop = bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x60\x00\x00\x60\x00\x00\xf0\x00\x00\xf0\x00\x01\xf8\x00\x03\xfc\x00\x07\xfe\x00\x0f\xff\x00\x1f\xff\x80\x3f\xff\xc0\x3f\xff\xc0\x7f\xff\xe0\xff\xff\xf0\xe7\xff\xf0\xf3\xff\xf0\xf3\xff\xf0\xf3\xff\xf0\x79\xff\xe0\x7c\x7f\xe0\x3e\x7f\xc0\x1f\xff\x80\x0f\xff\x00\x01\xf8\x00')
# Clear the display
oled.fill(0)
# Set text position and font size
text_x = 33
text_y = 20
# Display pump status
if pump_on:
oled.text("PUMP ON", text_x, text_y)
else:
oled.text("PUMP OFF", text_x, text_y)
fb = framebuf.FrameBuffer(water_drop, 20, 25, framebuf.MONO_HLSB)
oled.blit(fb, 55, 30)
# Update the display
oled.show()
def display_dashboard(oled, temperature, humidity, water_level):
# Clear the display
oled.fill(0)
oled.show()
# Display temperature
oled.text("Temp: {:.1f} C".format(temperature), 0, 0)
# Display humidity
oled.text("Humidity: {:.1f}%".format(humidity), 0, 16)
# Calculate the width of the water level indicator
water_width = int((water_level / 100) * 128)
# Draw the water level indicator
oled.fill_rect(0, 48, water_width, 16, 1)
# Display water level percentage
oled.text("Water Lvl: {}%".format(water_level), 0, 32)
# Update the display
oled.show()
# Example usage with dummy values:
temperature = 25.4
humidity = 60.2
water_level = 100
# Display the dashboard
display_dashboard(oled, temperature, humidity, water_level)
sleep(3)
# Example usage with dummy values:
pump_on = True
# Display the pump status
display_pump_status(oled, pump_on)