12
12
13
13
` pip install pyserial `
14
14
15
- ## Prática
15
+ ## Prática Python
16
16
17
17
``` python
18
18
import serial
@@ -26,4 +26,31 @@ while True:
26
26
27
27
retorno = arduino.readline().decode(' ascii' )
28
28
print (' Retorno: ' + retorno)
29
- ```
29
+ ```
30
+
31
+ ## Prática Arduino
32
+
33
+ ``` cpp
34
+ #define led 13 // Porta onde o led está conectado
35
+
36
+ void setup (){
37
+ Serial.begin(9600); // Velocidade padrão para comunicação
38
+ pinMode (led, OUTPUT); // Porta onde o led será acionado, configurado como saida
39
+ }
40
+
41
+ void loop (){
42
+ if (Serial.available() > 0){
43
+ char leitura = Serial.read(); // Variavel que receberá os valores enviados pelo programa em python
44
+
45
+ if(leitura == 'l'){
46
+ digitalWrite(led, HIGH); // Liga a porta 13 se o valor recebido for 1
47
+ Serial.println("Acionou led!"); // Envia mensagem para a porta Serial
48
+ }
49
+
50
+ if(leitura == 'd'){
51
+ digitalWrite(led, LOW); // Desliga a porta 13 se o valor recebido for 2
52
+ Serial.println("Desligou led!"); // Envia mensagem para a porta Serial
53
+ }
54
+ }
55
+ }
56
+ ```
0 commit comments