Skip to content

Commit

Permalink
Merge pull request #5 from GEdO23/dev
Browse files Browse the repository at this point in the history
Cap 8 - Python x IoT
  • Loading branch information
Gabriel Eringer authored Sep 21, 2024
2 parents 3fde675 + 463207c commit 995cdbd
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 0 deletions.
19 changes: 19 additions & 0 deletions arduino/comunicacao.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import serial
from serial.tools import list_ports

# lista as portas do arduino.
for port in list_ports.comports():
print("Dispositivo: {} - porta: {} ".format(port.description, port.device))

conexao = serial.Serial('COM1', 115200)

acao = input("Digite:\n<L> para Ligar\n<D> para Desligar: ").upper()
while acao == 'L' or acao == 'D':
if acao == 'L':
conexao.write(b'1')
else:
conexao.write(b'0')
acao = input("Digite:\n<L> para Ligar\n<D> para Desligar: ").upper()

conexao.close()
print("Conexão encerrada.")
23 changes: 23 additions & 0 deletions arduino/controle_pela_luz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import serial
from serial.tools import list_ports

conexao = ""
for port in list_ports.comports():
print("Dispositivo: {} - porta: {} ".format(port.description, port.device))
if "ARDUINO" in port.description.upper():
try:
conexao = serial.Serial(port.device, 115200)
print("Conexão realizada com {}.".format(conexao.portstr))
except:
pass

if conexao != "":
print("Iniciando...")
while True:
print("Recebendo dados...")
resposta = conexao.readline()
valor = float(resposta.decode())
print(valor)
if valor < 700:
conexao.write(b'1')
conexao.close()
17 changes: 17 additions & 0 deletions arduino/led_control_luminosidade/led_control_luminosidade.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
void setup() {
pinMode(10, OUTPUT);
Serial.begin(115200);
}

void loop() {
int valorRecebido;
int luz = analogRead(1);
Serial.println(luz);
delay(500);
valorRecebido = Serial.read();
if (valorRecebido == '0') {
digitalWrite(10, LOW);
} else {
digitalWrite(10, HIGH);
}
}
16 changes: 16 additions & 0 deletions arduino/led_serial_liga_desliga/led_serial_liga_desliga.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
void setup() {
pinMode(10, OUTPUT);
Serial.begin(115200);
}

void loop() {
int valorRecebido;
if (Serial.available()) {
valorRecebido = Serial.read();
if (valorRecebido == '0') {
digitalWrite(10, LOW);
} else {
digitalWrite(10, HIGH);
}
}
}
18 changes: 18 additions & 0 deletions arduino/recebe_luminosidade.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import serial
from serial.tools import list_ports

conexao = ""
for port in list_ports.comports():
print("Dispositivo: {} - porta: {} ".format(port.description, port.device))
if "ARDUINO" in port.description.upper():
try:
conexao = serial.Serial(port.device, 115200)
print("Conexão realizada com {}.".format(conexao.portstr))
except:
pass

if conexao != "":
while True:
resposta = conexao.readline()
print(float(resposta.decode()))
conexao.close()
9 changes: 9 additions & 0 deletions arduino/sensor_luminosidade/sensor_luminosidade.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
void setup() {
Serial.begin(115200);
}

void loop() {
int luz = analogRead(1);
Serial.println(luz);
delay(1000);
}

0 comments on commit 995cdbd

Please sign in to comment.