import machine
import time
import urandom as random # Import urandom for MicroPython random operations
# Define GPIO pins
BUTTON_PIN = 14
BUTTON_PIN2 = 17
RED_LED_PIN = 28
GREEN_LED_PIN = 5
# Define the list of yes/no questions
questions = [
"Have you ever lied to get out of trouble?",
"Do you sing in the shower?",
"Do you have a secret talent no one knows about?",
"Do you have a crush on someone right now?",
"Have you ever cheated on a test?",
"Have you ever regretted something you did not say?",
"Do you believe in love at first sight?",
"Have you ever pretended to be sick to get out of something?",
"Do you enjoy cooking?",
"Do you think aliens exist?"
]
# Dummy LCD function for simulation
def lcd_puts(message):
print("LCD:", message)
# Set up GPIO pins
button1 = machine.Pin(BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_UP)
button2 = machine.Pin(BUTTON_PIN2, machine.Pin.IN, machine.Pin.PULL_UP)
red_led = machine.Pin(RED_LED_PIN, machine.Pin.OUT)
green_led = machine.Pin(GREEN_LED_PIN, machine.Pin.OUT)
# Function to shuffle questions list manually
def shuffle_questions():
shuffled_questions = questions[:] # Create a copy of the questions list
for i in range(len(shuffled_questions) - 1, 0, -1):
j = random.randint(0, i)
shuffled_questions[i], shuffled_questions[j] = shuffled_questions[j], shuffled_questions[i]
return shuffled_questions
# Function to randomly choose a question
def choose_question():
shuffled_questions = shuffle_questions()
return shuffled_questions[0] # Select the first question after shuffling
# Function to randomly choose and light an LED
def choose_led():
choice = random.choice(['red', 'green'])
if choice == 'red':
red_led.value(1)
green_led.value(0)
return "lie"
elif choice == 'green':
red_led.value(0)
green_led.value(1)
return "truth"
# Function to display a question and get the user's response (yes/no)
def ask_question(question):
lcd_puts(question)
while True:
if not button1.value():
return "yes"
elif not button2.value():
return "no"
time.sleep(0.1)
try:
while True:
question = choose_question()
response = ask_question(question)
lcd_puts("You answered: " + response)
time.sleep(1)
time.sleep(5) # Wait for 5 seconds
result = choose_led()
lcd_puts(result)
while not button1.value() or not button2.value(): # Wait for both buttons to be released
time.sleep(0.1)
time.sleep(0.1)
except KeyboardInterrupt:
pass