Example #1
0
 
""" Configurando GPIO """
# Configurando o modo do GPIO como BCM
gpio.setmode(gpio.BCM)
 
# Configurando PIN's como INPUT e modo pull-down interno
gpio.setup(Porta, gpio.IN, pull_up_down = gpio.PUD_DOWN)
gpio.setup(Tranca, gpio.IN, pull_up_down = gpio.PUD_DOWN)
 
# Adicionando um evento ao GPIO 23 na mudança RISING 0V[LOW] -> 3.3V[HIGH]
gpio.add_event_detect(Porta, gpio.BOTH, callback=action_event_registrar)
gpio.add_event_detect(Tranca, gpio.BOTH, callback=action_event_registrar) 
 
while True:
    try:
        if gpio.event_detected(Porta):
            action_event_button(Porta)
            #gpio.remove_event_detect(PIN)
        
        else:
                    print("Botão Desligado")
        if gpio.event_detected(Tranca):
            action_event_button(Tranca)
            #gpio.remove_event_detect(PIN)
        
        else:
                    print("Botão Desligado")
 
        time.sleep(1)
    except (KeyboardInterrupt):
        print("Saindo...")
Example #2
0

def measure_temp():
    temp = os.popen("sudo vcgencmd measure_temp").readline()
    return (temp.replace("temp=",""))
def temp_cpu():
        
    a =open("/sys/class/thermal/thermal_zone0/temp")
    temp = a.readline()
    a.close()
    return (float (temp.replace("temp=","")))/1000

x = 0
flag = False;
while True :
    if gpio.event_detected(PIN):
        break;
while x<(60):
   if gpio.event_detected(PIN):
       flag = True
       
   
   # now = datetime.now()
   # print now.hour
   # print time.strftime('%l:%M:%S %p %Z on %b %d, %Y')
    arquivo.writelines(time.strftime('Horario da captura: %l:%M:%S %p %Z on %d\
    , %Y; ')+ 'Temperatura na CPU: '+str(temp_cpu())+'; Temperatura na GPU \
    :'+measure_temp())

    time.sleep(1)
    if flag: