-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from GEdO23/dev
Cap 8 - Python x IoT
- Loading branch information
Showing
6 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
arduino/led_control_luminosidade/led_control_luminosidade.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
arduino/led_serial_liga_desliga/led_serial_liga_desliga.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |