SunFounder ESP32 Starter Kit
(continued from previous page)
# IR receiver configuration
pin_ir = Pin(14, Pin.IN)
# Initialize the guessing game variables
lower = 0
upper = 99
pointValue = int(urandom.uniform(lower, upper))
count = 0
# Initialize the LCD1602 display
lcd = LCD()
# Initialize a new random value for the game
def init_new_value():
global pointValue, upper, lower, count
pointValue = int(urandom.uniform(lower, upper))
print(pointValue)
upper = 99
lower = 0
count = 0
return False
# Display messages on the LCD based on the game state
def lcd_show(result):
global count
lcd.clear()
if result == True:
string = "GAME OVER!\n"
string += "Point is " + str(pointValue)
else:
string = "Enter number: " + str(count) + "\n"
string += str(lower) + " < Point < " + str(upper)
lcd.message(string)
return
# Process the entered number and update the game state
def number_processing():
global upper, count, lower
if count > pointValue:
if count < upper:
upper = count
elif count < pointValue:
if count > lower:
lower = count
elif count == pointValue:
return True
count = 0
return False
# Process the key inputs from the IR remote control
def process_key(key):
global count, lower, upper, pointValue, result
(continues on next page)
3.39. 6.7 Guess Number 435