Hendra Kusumah
Published © GPL3+

Love Quote Generator

A randomize quote display based on Xiao ESP32C3 and micropython

BeginnerFull instructions provided1 hour340
Love Quote Generator

Things used in this project

Hardware components

XIAO ESP32C3
Seeed Studio XIAO ESP32C3
×1
Seeed Studio XIAO Expansion Board
Seeed Studio XIAO Expansion Board
×1

Software apps and online services

MicroPython
MicroPython

Story

Read more

Schematics

xiao expansion board

Code

main.py

MicroPython
from machine import Pin, SoftI2C
import ssd1306
import random
import time
import framebuf

# Define romance quote parts
beginnings = [
    "In your eyes, ", "With you, ", "Since we met, ", "In this world, ", 
    "When we touch, ", "You are my ", "In every moment, ", "Through it all, ", 
    "Between us, ", "Forever, "
]

middles = [
    "I see forever, ", "time stands still, ", "life feels right, ", "I find peace, ", 
    "fear disappears, ", "I feel whole, ", "stars align, ", "magic happens, ", 
    "the world fades, ", "destiny calls, "
]

endings = [
    "and I never want to let go.", "because you're my everything.", "this is our story.", 
    "you're my missing piece.", "our souls connect.", "everything feels perfect.", 
    "this is true love.", "you're my infinite.", "every moment is precious.", "you're my dream."
]

# Initialize I2C and SSD1306 OLED display
i2c = SoftI2C(scl=Pin(7), sda=Pin(6))
oled = ssd1306.SSD1306_I2C(128, 64, i2c)

# Initialize push button
button = Pin(3, Pin.IN, Pin.PULL_UP)  # Adjust pin if needed

# 16x16 pixel heart bitmap (each row is 2 bytes: 16 bits)
heart_bitmap = bytearray([
    0b00001110, 0b01110000,
    0b00111111, 0b11111000,
    0b01111111, 0b11111100,
    0b11111111, 0b11111110,
    0b11111111, 0b11111110,
    0b11111111, 0b11111110,
    0b01111111, 0b11111100,
    0b00111111, 0b11111000,
    0b00011111, 0b11110000,
    0b00001111, 0b11100000,
    0b00000111, 0b11000000,
    0b00000011, 0b10000000,
    0b00000001, 0b00000000,
    0b00000000, 0b00000000,
    0b00000000, 0b00000000,
    0b00000000, 0b00000000
])

# Function to display heart splash screen
def display_heart():
    oled.fill(0)  # Clear screen
    fb = framebuf.FrameBuffer(heart_bitmap, 16, 16, framebuf.MONO_HLSB)
    oled.blit(fb, 56, 20)  # Center the heart
    oled.text("Love", 50, 40)  # Title text
    oled.text("Quote Generator", 5, 50)  # Title text
    oled.show()
    time.sleep(2)  # Display for 2 seconds

# Function to generate a random romance quote
def generate_romance_quote():
    return f"{random.choice(beginnings)}{random.choice(middles)}{random.choice(endings)}"

# Function to split text for OLED display
def split_text(text, max_line_length=16):
    words, lines, current_line = text.split(" "), [], ""
    for word in words:
        if len(current_line) + len(word) + 1 <= max_line_length:
            current_line += word + " "
        else:
            lines.append(current_line.strip())
            current_line = word + " "
    lines.append(current_line.strip())
    return lines

# Function to display quote on OLED
def display_quote(quote):
    oled.fill(0)
    lines, y = split_text(quote), 0
    for line in lines:
        oled.text(line, 0, y)
        y += 10  # Move text down
        if y > 54:
            break
    oled.show()

# Show the heart splash screen at startup
display_heart()

# Main loop
while True:
    if button.value() == 0:  # Button is pressed (active low)
        quote = generate_romance_quote()
        display_quote(quote)
        time.sleep(0.5)  # Debounce delay
        while button.value() == 0:  # Wait for button release
            pass
    time.sleep(0.1)
 

Credits

Hendra Kusumah
36 projects • 141 followers
Love hacking and making new things from IoT to robotics
Contact

Comments

Please log in or sign up to comment.