EasyManua.ls Logo

SunFounder ESP32

Default Icon
771 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
SunFounder ESP32 Starter Kit
lower = 0
upper = 99
pointValue = int(urandom.uniform(lower, upper))
count = 0
lower and upper bounds for the secret number.
The secret number (pointValue) randomly generated between lower and upper bounds.
The user’s current guess (count).
2. This function resets the guessing game values and generates a new secret number.
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
3. This function displays the current game status on the LCD screen.
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
If the game is over (result=True), it shows GAME OVER! and the secret number.
Otherwise, it shows the current guess (count) and the current guessing range (lower to upper)
4. This function processes the users current guess (count) and updates the guessing range.
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
If the current guess (count) is higher than the secret number, the upper bound is updated.
438 Chapter 3. For MicroPython User

Table of Contents