Advertisement
pkaislan

completecode

May 12th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.58 KB | None | 0 0
  1. # Imports
  2. import time
  3. from datetime import datetime
  4. import serial
  5. # Variaveis
  6.  
  7. if __name__ == '__main__':
  8.  
  9. #variaveis de Reles
  10.  
  11.  
  12.  
  13.  ligarrele1=str(chr(112))
  14.  desligarrele1=str(chr(113))
  15.  
  16.  
  17.  ligarrele2=str(chr(114))
  18.  desligarrele2=str(chr(115))
  19.  
  20.  
  21.  ligarrele3=str(chr(116))
  22.  desligarrele3=str(chr(117))
  23.  
  24.  
  25.  ligarrele4=str(chr(118))
  26.  desligarrele4=str(chr(119))
  27.  
  28.  
  29.  teste_conexao=str(chr(101))
  30.  
  31.  
  32. # Variaveis globais
  33.  
  34. aux = 0
  35.  
  36.  
  37. #Funcao para buscar dados da conexao
  38. while (True):
  39.  try:
  40.   print ("Obtendo informacoes da Conexao com o Arduino . . .\n")
  41.   time.sleep(2)
  42.   conectar = serial.Serial('COM3', 9600, timeout=1)
  43.   retornar_valor = conectar.read()
  44.   conectar.write(b'teste_conexao')
  45.   if (retornar_valor == b'' ):
  46.      print ("Conexao Estabelecida com Sucesso!\n")
  47.      time.sleep(2)
  48.      print ("Status da Porta: %s", conectar.isOpen())
  49.      print ("Arduino conectado: %s", conectar.name)
  50.      print ("Dump da configuracao: %s", conectar)
  51.   else:
  52.       print(retornar_valor)
  53.  except:
  54.     print("Nao e possivel estabelecer uma conexao!\n")
  55.     time.sleep(2)
  56.     print("Verifique se o Arduino esta ligado e conectado ao computador!\n")
  57.     print("Conexao sera reiniciada em 10 segundos!")
  58.     time.sleep(10)
  59.  else:        
  60.      while (True):# Ligar e Desligar Aspersor 1
  61.              
  62.          today = datetime.now()
  63.          horas = today.hour
  64.          minutos = today.minutes
  65.          segundos = today.second
  66.          
  67.      if (horas == 16) and (minutos == 30):
  68.                    if ( aux == 0):
  69.                        conectar.write(b'ligarrele1')
  70.                        time.sleep(0.5)
  71.                        if (retornar_valor == b''):
  72.                            print ("O Aspersor 1 foi iniciado")
  73.                        else:
  74.                             print ("Retorno da serial: %s", retornar_valor)
  75.                             aux = 1
  76.                    else:
  77.                      aux = 0    
  78.        
  79.      
  80.    
  81.      if (horas == 16) and (minutos == 50):
  82.                        if ( aux == 0):
  83.                            conectar.write(b'desligarrele1')
  84.                            time.sleep(0.5)
  85.                            if (retornar_valor == b''):
  86.                                 print ("O Aspersor 1 foi encerrado")
  87.                            else:
  88.                             print ("Retorno da serial: %s", retornar_valor)
  89.                             aux = 1
  90.                        else:
  91.                          aux = 0  
  92.  
  93.    
  94.    
  95.                 # Ligar e Desligar Aspersor 2
  96.      if (horas == 16) and (minutos == 51):
  97.                     if ( aux == 0):
  98.                         conectar.write(b'ligarrele2')
  99.                         time.sleep(0.5)
  100.                         if (retornar_valor == b''):
  101.                           print ("O Aspersor 2 foi iniciado")
  102.                         else:
  103.                           print ("Retorno da serial: %s", retornar_valor)
  104.                           aux = 1
  105.                     else:
  106.                       aux = 0    
  107.        
  108.      
  109.    
  110.      if (horas == 17) and (minutos == 11):
  111.                    if ( aux == 0):
  112.                        conectar.write(b'desligarrele2')
  113.                        time.sleep(0.5)
  114.                        if (retornar_valor == b''):
  115.                          print ("O Aspersor 2 foi encerrado")
  116.                        else:
  117.                          print ("Retorno da serial: %s", retornar_valor)
  118.                          aux = 1
  119.                    else:
  120.                      aux = 0  
  121.          
  122.          
  123.                      
  124.                  # Ligar e Desligar Aspersor 3
  125.      if (horas == 17) and (minutos == 12):
  126.                   if ( aux == 0):
  127.                      conectar.write(b'ligarrele3')
  128.                      time.sleep(0.5)
  129.                      if (retornar_valor == b''):
  130.                         print ("O Aspersor 3 foi iniciado")
  131.                      else:
  132.                         print ("Retorno da serial: %s", retornar_valor)
  133.                         aux = 1
  134.                   else:
  135.                      aux = 0    
  136.        
  137.      
  138.    
  139.      if (horas == 17) and (minutos == 32):
  140.                   if ( aux == 0):
  141.                      conectar.write(b'desligarrele3')
  142.                      time.sleep(0.5)
  143.                      if (retornar_valor == b''):
  144.                        print ("O Aspersor 1 foi encerrado")
  145.                      else:
  146.                         print ("Retorno da serial: %s", retornar_valor)
  147.                         aux = 1
  148.                   else:
  149.                      aux = 0  
  150.          
  151.          
  152.                    # Ligar e Desligar Luzes
  153.      if (horas == 17) and (minutos == 30):
  154.                   if ( aux == 0):
  155.                      conectar.write(b'ligarrele4')
  156.                      time.sleep(0.5)
  157.                      if (retornar_valor == b''):
  158.                       print ("As luzes foram ligadas")
  159.                      else:
  160.                        print ("Retorno da serial: %s", retornar_valor)
  161.                        aux = 1
  162.                   else:
  163.                     aux = 0    
  164.        
  165.      
  166.    
  167.      if (horas == 6) and (minutos == 0):
  168.                   if ( aux == 0):
  169.                       conectar.write(b'desligarrele4')
  170.                       time.sleep(0.5)
  171.                       if (retornar_valor == b''):
  172.                        print ("As Luzes Foram Desligadas")
  173.                       else:
  174.                         print ("Retorno da serial: %s", retornar_valor)
  175.                         aux = 1
  176.                   else:
  177.                      aux = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement