# L4b - Program test si verificare semnale stmuli perceptron cu Pico # Stimulii de intrare provin de la 10 fotorezistente conectate # prin intermediul unui multiplexor analogic de tip CD 40 from machine import Pin, ADC import time import _thread # Conexiuni multiplexor analog fan=_thread.allocate_lock() # fanion mutex 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 # Conexiuni LED-uri red = Pin(16, Pin.OUT) green= Pin(17, Pin.OUT) blue = Pin(18, Pin.OUT) amber = Pin(19, Pin.OUT) rgb = Pin(6,Pin.OUT) red.high() # stare initiala LED-uri blue.high() amber.high() green.high() rgb.low() # LED putere blue conectat cu ULN inversor global x0,x1,x2,x3,x4,x5,x6,x7,x8,x9 # stimuli intrare 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 while 1: global x0,x1,x2,x3,x4,x5,x6,x7,x8,x9 #print(x0,x1,x2,x3,x4,x5,x6,x7,x8,x9) rgb.high() # aprind power RGB time.sleep(0.5) rgb.low() time.sleep(0.5) print(x0,x1,x2,x3,x4,x5,x6,x7,x8,x9) #print ("ceva merge",x9)