from machine import Pin
import lcd
from time import sleep
import random
rs=Pin(12,Pin.OUT)
en=Pin(11,Pin.OUT)
d4=Pin(10,Pin.OUT)
d5=Pin(9,Pin.OUT)
d6=Pin(8,Pin.OUT)
d7=Pin(7,Pin.OUT)
button=Pin(14,Pin.IN)
previous_button=0
player_col=1
player_row=1
obstacle_col=15
obstacle_row=random.randint(0,1)
lcd.init(rs,en,d4,d5,d6,d7)
lcd.clear()
lcd.load_custom_chars()
while True:
current_button=button.value()
if current_button==1 and previous_button==0:
if player_row==1:
player_row=0
else:
player_row=1
previous_button=current_button
lcd.clear()
lcd.setCursor(player_col,player_row)
lcd.print(chr(0))
lcd.setCursor(obstacle_col,obstacle_row)
lcd.print(chr(1))
if obstacle_col==player_col and obstacle_row==player_row:
lcd.setCursor(0,0)
lcd.print("Game Over!")
lcd.setCursor(0,1)
lcd.print("Restarting...")
sleep(2)
player_row=1
obstacle_col=15
obstacle_row=random.randint(0,1)
lcd.clear()
continue
obstacle_col=obstacle_col-1
if obstacle_col<0:
obstacle_col=15
obstacle_row=random.randint(0,1)
sleep(0.2)