#MakeLottryUsingPico.py
#Stepper motor:28BY-48 5VDC
#Stepper board:Using DRV8833
#LCD 1002 i2c display
##November 25,2021 finished
import machine
import utime
from machine import I2C,Pin
from pico_i2c_lcd import I2cLcd
import urandom
SW1=Pin(4,Pin.IN,Pin.PULL_DOWN)
SW2=Pin(5,Pin.IN,Pin.PULL_DOWN)
IN1=Pin(6,Pin.OUT)
IN2=Pin(7,Pin.OUT)
IN3=Pin(8,Pin.OUT)
IN4=Pin(9,Pin.OUT)
wait_ms=2
State=False
i2c=I2C(0,sda=Pin(0),scl=Pin(1),freq=400000)
I2C_ADDR=i2c.scan()[0]
lcd=I2cLcd(i2c,I2C_ADDR,2,16)
def stepperstart():
IN1.value(1)
IN2.value(0)
IN3.value(0)
IN4.value(1)
utime.sleep_ms(wait_ms)
IN1.value(1)
IN2.value(1)
IN3.value(0)
IN4.value(0)
utime.sleep_ms(wait_ms)
IN1.value(0)
IN2.value(1)
IN3.value(1)
IN4.value(0)
utime.sleep_ms(wait_ms)
IN1.value(0)
IN2.value(0)
IN3.value(1)
IN4.value(1)
utime.sleep_ms(wait_ms)
def stepperstop():
IN1.value(0)
IN2.value(0)
IN3.value(0)
IN4.value(0)
#utime.sleep(2)
def openlcd():
lcd.putstr("Bit 1 to 6" + "\n")
lcd.putstr("Long press sw" + "\n")
lcd.clear
def stoplcd():
i=urandom.randrange(1,6)
istring =str(i)
lcd.putstr("Number is " + istring +"\n")
lcd.putstr(""+"\n")
lcd.clear
openlcd()
while True:
if SW1.value()==1:
State=True
if SW2.value()==1:
State=False
if State==True :
stepperstart()
if State==False and SW2.value()==1 and SW1.value()==0:
stepperstop()
stoplcd()
