# from machine import Pin,I2C,Timer
# from pico_i2c_lcd import I2cLcd
# import utime as ut
# import random
# sda=Pin(0)
# scl=Pin(1)
# i2c=I2C(0,sda=sda,scl=scl,freq=400000)
# device=i2c.scan()
# if len(device)<=0:
# print("No devices are connectecd")
# else:
# print(f"Address of the device connectecd :{hex(device[0])}")
# i2caddr=device[0]
# lcd=I2cLcd(i2c,i2caddr,2,16)
# # a=1
# # def fn(timer):
# # lcd.clear()
# # global a
# # lcd.putstr(str(a))
# # a+=1
# # timer=Timer(freq=1,mode=Timer.PERIODIC,callback=fn)
# # led=[]
# # for i in range(1,6):
# # led.append(Pin(i+1,Pin.OUT))
# # connections=[1,2,3,4,5] #2,3,4,5,6
# # a=random.choice(connections)
# # lcd.putstr(str(a))
# # led[a-1].value(1)
# # lcd.putstr("Kunal")
# # ut.sleep_ms(200)
# # lcd.clear()
# # lcd.putstr("Raju")
# # a=5
# # b=1
# # def fn(timer):
# # lcd.clear()
# # global a,b
# # lcd.putstr(str(a)+'X'+str(b)+'='+str(a*b))
# # b+=1
# # count = 0
# # def fn(timer):
# # global count
# # lcd.clear()
# # lcd.putstr(f"Counter: {count}")
# # count += 1
# # ut.sleep(1)
# # timer=Timer(freq=1,mode=Timer.PERIODIC,callback=fn)
# message = "This is a scrolling text demo. "
# while True:
# for i in range(len(message)):
# lcd.move_to(0,0)
# lcd.putstr(message[i:i+16]) # Display a segment
# ut.sleep(0.3)
from machine import Pin,I2C
import time,random
from pico_i2c_lcd import I2cLcd
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(hex(devices[0]))
i2c_addr = devices[0]
lcd=I2cLcd(i2c,i2c_addr,2,16)
target = (random.randint(0, 15), random.randint(0, 1)) # LCD coordinates
ball = (random.randint(0, 15), random.randint(0, 1))
jumps = 0
lcd.clear()
lcd.putstr(f"Target: {target}")
time.sleep(1)
while ball != target:
lcd.clear()
lcd.move_to(ball[0],ball[1])
lcd.putstr("O")
lcd.move_to(target[0],target[1])
lcd.putstr("X")
ball = (random.randint(0, 15), random.randint(0, 1))
jumps += 1
time.sleep(1)
lcd.clear()
lcd.putstr(f"Jumps: {jumps}")
time.sleep(2)
lcd.clear()
lcd.putstr("You Win!")