Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Rafael Gonçalves
Oficinas hardware livre
Commits
1d195c02
Commit
1d195c02
authored
6 months ago
by
Rafael Gonçalves
Browse files
Options
Download
Email Patches
Plain Diff
Adiciona ex. sobre sensor LDR
parent
07da6718
01-helloWorld
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+7
-4
README.md
sensor.ino
+59
-0
sensor.ino
with
66 additions
and
4 deletions
+66
-4
README.md
View file @
1d195c02
...
...
@@ -5,8 +5,11 @@ Experimentos práticos com arduino.
## Módulo 1: Olá mundo
1.
**Piscar um led**
-
arquivo: blinkLed.ino
-
simulação: https://www.tinkercad.com/things/d8T2GBQUBM4-ohl1-blinkled
-
arquivo: blinkLed.ino
-
simulação: https://www.tinkercad.com/things/d8T2GBQUBM4-ohl1-blinkled
2.
**Leitura e escrita no console via serial**
-
arquivo: serial.ino
-
simulação: https://www.tinkercad.com/things/eRtvVgsBCxE-ohl2-serial
-
arquivo: serial.ino
-
simulação: https://www.tinkercad.com/things/eRtvVgsBCxE-ohl2-serial
3.
**Leitura de sensor**
-
arquivo: sensor.ino
-
simulação: https://www.tinkercad.com/things/iNR8vR5nCYf-ohl3-sensor
This diff is collapsed.
Click to expand it.
sensor.ino
0 → 100644
View file @
1d195c02
const
int
PINO_LED
=
13
;
// pino físico do arduino
const
int
TEMPO_DE_ESPERA
=
1000
;
// 1000ms = 1s
const
int
PINO_LDR
=
A0
;
int
byteRecebido
;
int
automatico
=
true
;
int
calibragemSensor
=
500
;
float
valorSensor
;
// Configuração
void
setup
()
{
pinMode
(
PINO_LDR
,
INPUT
);
pinMode
(
PINO_LED
,
OUTPUT
);
// Inicia comunicação serial
Serial
.
begin
(
9600
);
// Garante serial conectado
while
(
!
Serial
);
}
// Laço de execução
void
loop
()
{
// Se receber um byte
if
(
Serial
.
available
()
>
0
)
{
byteRecebido
=
Serial
.
read
();
if
(
byteRecebido
==
'L'
)
{
automatico
=
false
;
digitalWrite
(
LED_BUILTIN
,
HIGH
);
Serial
.
println
(
"
\n
Ligado"
);
}
else
if
(
byteRecebido
==
'D'
)
{
automatico
=
false
;
digitalWrite
(
LED_BUILTIN
,
LOW
);
Serial
.
println
(
"
\n
Desligado"
);
}
else
if
(
byteRecebido
==
'A'
)
{
automatico
=
true
;
Serial
.
println
(
"
\n
Automático"
);
}
}
if
(
automatico
)
{
valorSensor
=
analogRead
(
PINO_LDR
);
Serial
.
print
(
"Valor do sensor: "
);
Serial
.
println
(
valorSensor
);
if
(
valorSensor
>=
calibragemSensor
){
digitalWrite
(
LED_BUILTIN
,
LOW
);
}
else
{
digitalWrite
(
LED_BUILTIN
,
HIGH
);
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help