You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
898 B
33 lines
898 B
from machine import Pin,ADC
|
|
class Barra16:
|
|
|
|
#CONSTRUCTOR
|
|
def __init__(self,s0,s1,s2,s3,out):
|
|
self.__s0=Pin(s0,Pin.OUT)
|
|
self.__s1=Pin(s1,Pin.OUT)
|
|
self.__s2=Pin(s2,Pin.OUT)
|
|
self.__s3=Pin(s3,Pin.OUT)
|
|
self.__out=ADC(Pin(out))
|
|
|
|
#METODOS PRIVADOS
|
|
def __read(self,x):
|
|
bits=bin(x)
|
|
bits=bits.split("b")[1]
|
|
for i in range (len(bits),4):
|
|
bits="0"+bits
|
|
self.__s0.value(bits[3]=='1')
|
|
self.__s1.value(bits[2]=='1')
|
|
self.__s2.value(bits[1]=='1')
|
|
self.__s3.value(bits[0]=='1')
|
|
return self.__out.read_u16()
|
|
|
|
#METODOS PUBLICOS
|
|
def getPos(self):
|
|
pos=0
|
|
sen=0
|
|
for x in range(16):
|
|
v=self.__read(x)
|
|
sen+=1 if v>50000 else 0
|
|
pos+=500*(x+1) if v>50000 else 0
|
|
return -1 if sen==0 else (pos/sen)-4250
|
|
|