Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Imports
- import time
- from datetime import datetime
- import serial
- # Variaveis
- if __name__ == '__main__':
- #variaveis de Reles
- ligarrele1=str(chr(112))
- desligarrele1=str(chr(113))
- ligarrele2=str(chr(114))
- desligarrele2=str(chr(115))
- ligarrele3=str(chr(116))
- desligarrele3=str(chr(117))
- ligarrele4=str(chr(118))
- desligarrele4=str(chr(119))
- teste_conexao=str(chr(101))
- # Variaveis globais
- aux = 0
- #Funcao para buscar dados da conexao
- while (True):
- try:
- print ("Obtendo informacoes da Conexao com o Arduino . . .\n")
- time.sleep(2)
- conectar = serial.Serial('COM3', 9600, timeout=1)
- retornar_valor = conectar.read()
- conectar.write(b'teste_conexao')
- if (retornar_valor == b'' ):
- print ("Conexao Estabelecida com Sucesso!\n")
- time.sleep(2)
- print ("Status da Porta: %s", conectar.isOpen())
- print ("Arduino conectado: %s", conectar.name)
- print ("Dump da configuracao: %s", conectar)
- else:
- print(retornar_valor)
- except:
- print("Nao e possivel estabelecer uma conexao!\n")
- time.sleep(2)
- print("Verifique se o Arduino esta ligado e conectado ao computador!\n")
- print("Conexao sera reiniciada em 10 segundos!")
- time.sleep(10)
- else:
- while (True):# Ligar e Desligar Aspersor 1
- today = datetime.now()
- horas = today.hour
- minutos = today.minutes
- segundos = today.second
- if (horas == 16) and (minutos == 30):
- if ( aux == 0):
- conectar.write(b'ligarrele1')
- time.sleep(0.5)
- if (retornar_valor == b''):
- print ("O Aspersor 1 foi iniciado")
- else:
- print ("Retorno da serial: %s", retornar_valor)
- aux = 1
- else:
- aux = 0
- if (horas == 16) and (minutos == 50):
- if ( aux == 0):
- conectar.write(b'desligarrele1')
- time.sleep(0.5)
- if (retornar_valor == b''):
- print ("O Aspersor 1 foi encerrado")
- else:
- print ("Retorno da serial: %s", retornar_valor)
- aux = 1
- else:
- aux = 0
- # Ligar e Desligar Aspersor 2
- if (horas == 16) and (minutos == 51):
- if ( aux == 0):
- conectar.write(b'ligarrele2')
- time.sleep(0.5)
- if (retornar_valor == b''):
- print ("O Aspersor 2 foi iniciado")
- else:
- print ("Retorno da serial: %s", retornar_valor)
- aux = 1
- else:
- aux = 0
- if (horas == 17) and (minutos == 11):
- if ( aux == 0):
- conectar.write(b'desligarrele2')
- time.sleep(0.5)
- if (retornar_valor == b''):
- print ("O Aspersor 2 foi encerrado")
- else:
- print ("Retorno da serial: %s", retornar_valor)
- aux = 1
- else:
- aux = 0
- # Ligar e Desligar Aspersor 3
- if (horas == 17) and (minutos == 12):
- if ( aux == 0):
- conectar.write(b'ligarrele3')
- time.sleep(0.5)
- if (retornar_valor == b''):
- print ("O Aspersor 3 foi iniciado")
- else:
- print ("Retorno da serial: %s", retornar_valor)
- aux = 1
- else:
- aux = 0
- if (horas == 17) and (minutos == 32):
- if ( aux == 0):
- conectar.write(b'desligarrele3')
- time.sleep(0.5)
- if (retornar_valor == b''):
- print ("O Aspersor 1 foi encerrado")
- else:
- print ("Retorno da serial: %s", retornar_valor)
- aux = 1
- else:
- aux = 0
- # Ligar e Desligar Luzes
- if (horas == 17) and (minutos == 30):
- if ( aux == 0):
- conectar.write(b'ligarrele4')
- time.sleep(0.5)
- if (retornar_valor == b''):
- print ("As luzes foram ligadas")
- else:
- print ("Retorno da serial: %s", retornar_valor)
- aux = 1
- else:
- aux = 0
- if (horas == 6) and (minutos == 0):
- if ( aux == 0):
- conectar.write(b'desligarrele4')
- time.sleep(0.5)
- if (retornar_valor == b''):
- print ("As Luzes Foram Desligadas")
- else:
- print ("Retorno da serial: %s", retornar_valor)
- aux = 1
- else:
- aux = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement