Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 98151d9

Browse files
Update arduino-python.md
1 parent 996c694 commit 98151d9

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

‎codes/Serial/arduino-python.md‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
`pip install pyserial`
1414

15-
## Prática
15+
## Prática Python
1616

1717
```python
1818
import serial
@@ -26,4 +26,31 @@ while True:
2626

2727
retorno = arduino.readline().decode('ascii')
2828
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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /