from machine import Pin, I2C
import utime
import urandom
from pico_i2c_lcd import I2cLcd
from lcd_api import LcdApi
sda = Pin(0)
scl = Pin(1)
i2c = I2C(0,sda=sda,scl=scl,freq=400000)
devices = i2c.scan()
if len(devices) <= 0:
print("no devices found")
else:
print(devices[0])
i2caddr = devices[0]
lcd = I2cLcd(i2c,i2caddr,2,16)
# lcd.putstr("Naman")
# for i in range(1,1000):
# lcd.putstr(str(i))
# utime.sleep(0.5)
# lcd.clear()
# for i in range(0,5):
# num = urandom.randint(0, 5)
# lcd.putstr(str(num))
# utime.sleep(0.5)
# lcd.clear()
# utime.sleep(0.5)
# leds = [Pin(3, Pin.OUT), Pin(6, Pin.OUT), Pin(12, Pin.OUT), Pin(13, Pin.OUT), Pin(14, Pin.OUT)]
# while True:
# random_number = random.randint(1,5)
# for led_pins in leds:
# led_pins.value(0)
# leds[random_number-1].value(1)
# lcd.putstr("Random number is : "+str(random_number))
# utime.sleep(1)
# lcd.clear()
# y = int(input("Enter a number: "))
# for i in range(1,11):
# ans = y*i
# lcd.putstr(f"{y} * {i} = {ans}")
# utime.sleep(0.5)
# lcd.clear()
# text = input("Enter text: ")
# while True:
# tmp = text
# for i in range(0, 9):
# lcd.move_to(i,0)
# if(i+len(tmp) > 20):
# break;
# lcd.putstr(text)
# utime.sleep(0.2)
# lcd.clear()
x = int(input("Enter the target location x coord (<2): "))
y = int(input("Enter the target location y coord (<16): "))
n = int(input("Enter Mximum number of moves available: "))
f = 0;
for i in range(0,n):
xn = urandom.randint(0, 1)
yn = urandom.randint(0, 15)
if xn == x and yn == y :
lcd.putstr(f"You Win in {i+1} Moves")
f = 1
break;
else:
print(xn,yn);
lcd.move_to(yn,xn);
lcd.putstr("0");
utime.sleep(1);
lcd.clear();
if f == 0 :
lcd.putstr("You lose")