# L4c - Program implementare perceptron cu activare fire luminos functie # de nivelul stimulilor # # # from machine import Pin, ADC import time import _thread # Conexiuni multiplexor analog 4067 s3= Pin(15, Pin.OUT) # selectie canale mux s2= Pin(14, Pin.OUT) s1= Pin(13, Pin.OUT) s0= Pin(12, Pin.OUT) e= Pin(11, Pin.OUT) # strobe mux activ in zero #ad=ADC(4) # sensor temperatura ad= ADC(Pin(27, mode=Pin.IN)) # instanta convertor A/D fan=_thread.allocate_lock() # fanion mutex # Conexiuni LED-uri red = Pin(16, Pin.OUT) green= Pin(17, Pin.OUT) blue = Pin(18, Pin.OUT) amber = Pin(19, Pin.OUT) red.high() # stare initiala LED-uri blue.high() amber.high() green.high() global x0,x1,x2,x3,x4,x5,x6,x7,x8,x9 # stimuli intrare w0=0.1 w1=0.2 w3=0.4 w5=0.6 w6=0.7 w7=0.8 w8=0.9 w9=0.99 global y def readx(): # task actualizare variabile x -ruleaza pe CPU 2 while 1: fan.acquire() # mutex global x0,x1,x2,x3,x4,x5,x6,x7,x8,x9 s3.low() # canal 0 s2.low() s1.low() s0.low() e.low() a=ad.read_u16()*3.3/65000 x0="{:.2f}".format(a) # formatare la 2 zecimale e.high() s3.low() # canal 1 s2.low() s1.low() s0.high() e.low() a=ad.read_u16()*3.3/65000 x1="{:.2f}".format(a) e.high() s3.low() # canal 2 s2.low() s1.high() s0.low() e.low() a=ad.read_u16()*3.3/65000 x2="{:.2f}".format(a) e.high() s3.low() # canal 3 s2.low() s1.high() s0.high() e.low() a=ad.read_u16()*3.3/65000 x3="{:.2f}".format(a) e.high() s3.low() # canal 4 s2.high() s1.low() s0.low() e.low() a=ad.read_u16()*3.3/65000 x4="{:.2f}".format(a) e.high() s3.low() # canal 5 s2.high() s1.low() s0.high() e.low() a=ad.read_u16()*3.3/65000 x5="{:.2f}".format(a) e.high() s3.low() # canal 6 s2.high() s1.high() s0.low() e.low() a=ad.read_u16()*3.3/65000 x6="{:.2f}".format(a) e.high() s3.low() # canal 7 s2.high() s1.high() s0.high() e.low() a=ad.read_u16()*3.3/65000 x7="{:.2f}".format(a) e.high() s3.high() # canal 8 s2.low() s1.low() s0.low() e.low() a=ad.read_u16()*3.3/65000 x8="{:.2f}".format(a) e.high() s3.high() # canal 9 s2.low() s1.low() s0.high() e.low() a=ad.read_u16()*3.3/65000 x9="{:.2f}".format(a) e.high() fan.release() # mutex _thread.start_new_thread(readx,()) # start task actualizare variabile intrare a=0 while 1: time.sleep(0.1) y=a+float(x0)*0.08+float(x1)*0.1+float(x2)*0.2+float(x3)*0.3+float(x4)*0.4+float(x5)*0.5+float(x6)*0.6+float(x7)*0.7+float(x8)*0.8+float(x9)*0.99 time.sleep(0.1) print(y) if y>100 : # fire blue.low() # time.sleep(0.1) blue.high() # sting y=0 # a=y