This repository has been archived by the owner on May 14, 2023. It is now read-only.
-
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.
Códigos para exemplos práticos adicionados
- Loading branch information
Showing
15 changed files
with
341 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,9 @@ | ||
|
||
void setup() { | ||
pinMode(5,OUTPUT);//define que o LED será ligado no pino 5 | ||
|
||
} | ||
|
||
void loop() { | ||
digitalWrite(5,HIGH); //Liga o LED | ||
} |
17 changes: 17 additions & 0 deletions
17
Acendendo_um_LED_com_um_botao/Acendendo_um_LED_com_um_botao.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 @@ | ||
int ler_botao = 9; // define uma variável onde vou guardar a leitura do botão | ||
int led = 7; | ||
|
||
void setup() | ||
{ | ||
pinMode(ler_botao, INPUT);//define a leitura do botão como entrada | ||
pinMode(led, OUTPUT);//e o led como saída | ||
} | ||
|
||
void loop() | ||
{ | ||
if (digitalRead(ler_botao) == 1) { // se o botão foi pressionado | ||
digitalWrite(led, HIGH); //acende o LED | ||
} | ||
//Quando soltar o botão, o código segue seu curso | ||
digitalWrite(led, LOW); //desliga o LED | ||
} |
20 changes: 20 additions & 0 deletions
20
Acendendo_um_LED_com_um_potenciometro/Acendendo_um_LED_com_um_potenciometro.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,20 @@ | ||
int potenciometro = A5; //pino onde vai ser ligado o potenciômetro | ||
int led = 3;// pino onde é ligado o LED | ||
|
||
int Leitura_Pot = 0;//Variável pra gardar a leitura do potenciômetro | ||
int Escrita_Led = 0; // Variável pra guardar o valor que deve ser escrito no LED | ||
|
||
void setup() | ||
{ | ||
pinMode(potenciometro, INPUT);//A leitura do potenciômetro é um input | ||
pinMode(led, OUTPUT);//E o LED um output | ||
} | ||
|
||
void loop() | ||
{ | ||
Leitura_Pot = analogRead(potenciometro);//realiza a leitura | ||
Escrita_Led = map(Leitura_Pot, 0, 1023, 0, 255);//faz a conversão de "escala" | ||
analogWrite(led, Escrita_Led);//escreve no led | ||
delay(100);//pra poder ver a alteração de brilho | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
Acendendo_um_Led_RBG_com_potenciometros/Acendendo_um_Led_RBG_com_potenciometros.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,28 @@ | ||
//Declaração dos potenciômetros | ||
int pt1 = A0; | ||
int pt2 = A1; | ||
int pt3 = A2; | ||
|
||
//Declaração dos LED | ||
int r = 9; | ||
int g = 10; | ||
int b = 11; | ||
|
||
void setup() | ||
{ | ||
//Os potenciômetros são entradas de dados e os pinos do led RBG, saídas. | ||
pinMode(pt1, INPUT); | ||
pinMode(r, OUTPUT); | ||
pinMode(pt2, INPUT); | ||
pinMode(g, OUTPUT); | ||
pinMode(pt3, INPUT); | ||
pinMode(b, OUTPUT); | ||
} | ||
|
||
void loop() | ||
{ | ||
analogWrite(r, map(analogRead(pt1), 0, 1023, 0, 255));//Faz a leitura, conversão de "escala" e escreve no respectivo pino | ||
analogWrite(g, map(analogRead(pt2), 0, 1023, 0, 255));//Faz a leitura, conversão de "escala" e escreve no respectivo pino | ||
analogWrite(b, map(analogRead(pt3), 0, 1023, 0, 255));//Faz a leitura, conversão de "escala" e escreve no respectivo pino | ||
delay(100); //Espera por 100 milissegundos | ||
} |
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,21 @@ | ||
//Declaração das variáveis onde vão ser colocados os terminais do LED | ||
//Um LED rbg tem três terminais, um para cada cor. | ||
int r = 6; | ||
int g = 3; | ||
int b = 5; | ||
|
||
void setup() | ||
{ | ||
//Todos são saídas de dados | ||
pinMode(r, OUTPUT); | ||
pinMode(g, OUTPUT); | ||
pinMode(b, OUTPUT); | ||
} | ||
|
||
void loop() | ||
{ | ||
//Escrever um valor para cada LED, os valores escritos em todos os pinos juntos dá a cor que queremos | ||
analogWrite(r, 153); | ||
analogWrite(g, 51); | ||
analogWrite(b, 153); | ||
} |
33 changes: 33 additions & 0 deletions
33
Acendendo_varios_Leds_com_um_potenciometro/Acendendo_varios_Leds_com_um_potenciometro.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,33 @@ | ||
int Escreve_Led = 0;//Valor a ser escrito | ||
|
||
//Declaração dos leds | ||
int led1 = 3; | ||
int led2 = 6; | ||
int led3 = 5; | ||
int led4 = 9; | ||
|
||
//potenciometro | ||
int pot = A5; | ||
|
||
void setup() | ||
{ | ||
pinMode(pot, INPUT);//O pino do potenciômetro é input | ||
//Todos os Leds são saídas de dados | ||
pinMode(led1, OUTPUT); | ||
pinMode(led2, OUTPUT); | ||
pinMode(led3, OUTPUT); | ||
pinMode(led4, OUTPUT); | ||
} | ||
|
||
void loop() | ||
{ | ||
Escreve_Led = map(analogRead(pot), 0, 1023, 0, 255);//Faz a leitura do potenciômetro e a conversão | ||
//Os dois primeiros LEDs acendem de acordo com a movimentação do potenciômetro | ||
analogWrite(led1, Escreve_Led); | ||
analogWrite(led2, Escreve_Led); | ||
//Os dois leds seguintes, apagam de acordo com a movimentação do potenciômetro | ||
//Isso é feito escrevendo o valor de aceso (255, valor de brilho total do LED) e diminuindo o valor lido | ||
analogWrite(led3, (255 - Escreve_Led)); | ||
analogWrite(led4, (255 - Escreve_Led)); | ||
delay(100); //delay pra ver a alteração de luz | ||
} |
23 changes: 23 additions & 0 deletions
23
Alterando_o_brilho_de_um_LED/Alterando_o_brilho_de_um_LED.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,23 @@ | ||
int Escreve_Led = 0; // Valor que vai ser escrito no LED | ||
|
||
int led = 3;// O LED estará ligado no pino 3 | ||
|
||
void setup() | ||
{ | ||
pinMode(led, OUTPUT);//Led definido como saída de dados | ||
} | ||
|
||
void loop() | ||
{ | ||
//este loop aumenta o brilho, indo de 0 até 255, que é o valor do brilho máximo de um LED | ||
for (Escreve_Led = 0; Escreve_Led < 255; Escreve_Led ++) { | ||
analogWrite(led, Escreve_Led); | ||
delay(15); // Wait for 15 millisecond(s) | ||
} | ||
|
||
//A variável escreve_led sai do loop anterior com o valor 255. Aqui, o brilho diminui, indo de 255 à zero | ||
for (Escreve_Led ; Escreve_Led > 0; Escreve_Led --) { | ||
analogWrite(led, Escreve_Led); | ||
delay(15); // Wait for 15 millisecond(s) | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...distancia_ultrassonico/Ativando_Led_e_soundbuzzr_com_sensor_de_distancia_ultrassonico.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,37 @@ | ||
int Leitura_sensor = 0; | ||
|
||
long readUltrasonicDistance(int triggerPin, int echoPin)//Função que faz a leitura do sensor | ||
{ | ||
//Basicamente, o pino trigger é desligado e ligado rapidamente, gerando um pulso. Esse pulso então é lido pelo echo pin, e resulta no valor da distância | ||
pinMode(triggerPin, OUTPUT); // limpa o trigger | ||
digitalWrite(triggerPin, LOW); //Seta o trigger pra desligado | ||
delayMicroseconds(2); | ||
digitalWrite(triggerPin, HIGH);// liga o trigger por 10 microssegundos | ||
delayMicroseconds(10); | ||
digitalWrite(triggerPin, LOW);// e o desliga de novo | ||
pinMode(echoPin, INPUT);//seta o pino de echo | ||
return pulseIn(echoPin, HIGH);//retorna o valor lido no pino echo | ||
} | ||
|
||
int soundbuzzer =13; //Liga o soundbuzzer no pino 13 | ||
int led = 4;//Liga o led no pino 4 | ||
|
||
void setup() | ||
{ | ||
Serial.begin(9600); //Inicia a conexão serial | ||
pinMode(led, OUTPUT); | ||
pinMode(soundbuzzer, OUTPUT); | ||
} | ||
|
||
void loop() | ||
{ | ||
Leitura_sensor = 0.01723 * readUltrasonicDistance(2, 3);//A leitura é calculada e armazenada. O pino trigger está conectado ao pino 2 e o echo ao 3. | ||
Serial.println(Leitura_sensor);//Imprime o valor de leitura no monitor serial | ||
if (Leitura_sensor < 60) {//Se a leitura for menor que 60, ou seja, tem alguma coisa a menos de 60 cm do sensor | ||
digitalWrite(led, HIGH);//O led acende | ||
tone(soundbuzzer, 523, 100); // tocar o soundbuzzer na frequência 523 por 100 milissegundos | ||
} else {//Caso contrário(se a leitura for maior que 60) | ||
digitalWrite(led, LOW);//O led é desligado | ||
noTone(soundbuzzer);//Não liga o soundbuzzer | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
Ativando_motor_com_sensor_ldr/Ativando_motor_com_sensor_ldr.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,35 @@ | ||
#include <Servo.h> | ||
|
||
//Variáveis de controle | ||
int Leitura_Luz = 0; | ||
int Leitura_anterior = 0; | ||
int escrita_Servo = 0; | ||
|
||
Servo servo_13;// Criação de um objeto servo chamado servo_13 | ||
|
||
void setup() | ||
{ | ||
pinMode(A5, INPUT);//O sensor será ligado ao pino A5 | ||
servo_13.attach(13);// servo 13 está conectado ao pino 13 | ||
|
||
} | ||
|
||
void loop() | ||
{ | ||
if (analogRead(A5) < 100) {// Primeiro é definida a leitura do estado atual de iluminação. Se for menor que 100, é considerado escuro, caso contrário é considerado claro. | ||
Leitura_Luz = 0; | ||
} else { | ||
Leitura_Luz = 1; | ||
} | ||
|
||
if (Leitura_Luz != Leitura_anterior) {//Se o estado atual for diferente da leitura que eu fiz anteriormente, ou seja, antes estava claro e agora está escuro, ou o contrário | ||
if (Leitura_Luz == 1) {//Se a leitura feita é um, significa que agora está claro, e antes escuro | ||
escrita_Servo = -180;//então decide que o motor vai virar 180 graus para a esquerda | ||
servo_13.write(escrita_Servo);//e se aplica essa mudança | ||
} else {//Senão, o valor de leitura luz é zero. O que significa que estava claro e agora está escuro | ||
escrita_Servo = 180;//então decide que o motor vai girar 180 graus para a direita | ||
servo_13.write(escrita_Servo);//se aplica essa mudança | ||
} | ||
Leitura_anterior = Leitura_Luz;//se atualiza a variável | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Ligando_um_LED_com_sensor_de_luminosidade/Ligando_um_LED_com_sensor_de_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,26 @@ | ||
int Leitura_Luz = 0;//Variável pra guardar o valor de leitura do sensor | ||
//LEDS | ||
int led1 = 3; | ||
int led2 = 4; | ||
//Sensor | ||
int ldr = A5; | ||
|
||
void setup(){ | ||
pinMode(ldr, INPUT);//a informação é lida do sensor | ||
Serial.begin(9600);//Inicia a conexão serial para podemos ver qual é a leitura do sensor. | ||
//Os leds são saída de dados | ||
pinMode(led1, OUTPUT); | ||
pinMode(led2, OUTPUT); | ||
} | ||
|
||
void loop(){ | ||
Leitura_Luz = analogRead(ldr);//Faz a leitura do sensor | ||
Serial.println(Leitura_Luz);//Mostra a leitura pro usuário | ||
if (Leitura_Luz >= 100) {//se a leitura do sensor for maior ou igual que 100, o que indica um certo nível de claridade, o led1 é aceso e o led 2 é apagado | ||
digitalWrite(led1, HIGH); | ||
digitalWrite(led2, LOW); | ||
} else { //Se a leitura for inferior a 100, o led2 é aceso e o led1 é apagado | ||
digitalWrite(led1, LOW); | ||
digitalWrite(led2, 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 @@ | ||
int botao = 12;//Pino onde vai ser ligado o botão | ||
int soundbuzzer = 8;//Pino onde vai ser ligado o soundbuzzer | ||
|
||
void setup() | ||
{ | ||
pinMode(botao, INPUT);//O valor do botão é lido, então ele é uma entrada de dados | ||
pinMode(soundbuzzer, OUTPUT); //o valor é escrito no soundbuzzer, então ele é uma saída de dados | ||
} | ||
|
||
void loop() | ||
{ | ||
if (digitalRead(botao) == 1) {//Se o botão for apertado | ||
tone(soundbuzzer, 294, 100); // tocar, no soundbuzzer, a frequência 294 por 100 milissegundos | ||
} | ||
else {//se o botão não for apertado | ||
noTone(soundbuzzer);//O soundbuzzer não toca | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...um_soundbuzzer_com_sensor_de_movimento/Ligando_um_soundbuzzer_com_sensor_de_movimento.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,23 @@ | ||
int Leitura_sensor = 0; // Variável para guardar a leitura do sensor | ||
|
||
int sensor = 3;//Pino onde o sensor vai estar conectado | ||
int soundbuzzer = 13;//Pino onde o sounsbuzzer vai estar conectado | ||
|
||
void setup() | ||
{ | ||
pinMode(sensor, INPUT);//O sensor é leitura de dados | ||
Serial.begin(9600);//Início da conexão serial | ||
pinMode(soundbuzzer, OUTPUT);//O soundbuzzer é saída de dados | ||
} | ||
|
||
|
||
void loop() | ||
{ | ||
Leitura_sensor = digitalRead(sensor);//faz a leitura | ||
Serial.println(Leitura_sensor);//Imprime no monitor serial | ||
if (Leitura_sensor == 1) {//Se a leitura for 1, ou seja, há movimento | ||
tone(soundbuzzer, 294, 100); // Toca o soundbuzzer na frequência 294 por 100 milissegundos | ||
} else {//se não houver movimento | ||
noTone(13);//o soundbuzzer não toca | ||
} | ||
} |
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,31 @@ | ||
int led1 = 5;//crio variáveis para guardar onde os pinos dos LEDs serão ligados | ||
int led2 = 6; | ||
int led3 = 7; | ||
int led4 = 8; | ||
|
||
void setup() { | ||
pinMode(led1, OUTPUT); //define que o LED será ligado no pino definido na variável, e que vai ser uma saida de dados | ||
pinMode(led2, OUTPUT); | ||
pinMode(led3, OUTPUT); | ||
pinMode(led4, OUTPUT); | ||
} | ||
|
||
void loop() { | ||
//Primeiro estado | ||
digitalWrite(led1, HIGH); //Ligado | ||
digitalWrite(led2, LOW); //Desligado | ||
digitalWrite(led3, HIGH); //Ligado | ||
digitalWrite(led4, LOW); //Desligado | ||
|
||
//espera 1 segundo | ||
delay(1000);//espera 1 segundo | ||
|
||
//Segundo estado | ||
digitalWrite(led1, LOW); //Desligado | ||
digitalWrite(led2, HIGH); //Ligado | ||
digitalWrite(led3, LOW); //Desligado | ||
digitalWrite(led4, HIGH); //Ligado | ||
|
||
//espera 1 segundo | ||
delay(1000); | ||
} |
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,14 @@ | ||
int led = 5;//crio uma variável para guardar em qual pino o LED vai estar colocado | ||
|
||
void setup() { | ||
pinMode(led, OUTPUT); //define que o LED será ligado no pino definido na variável, e que vai ser uma saida de dados | ||
|
||
} | ||
|
||
void loop() { | ||
digitalWrite(led, HIGH); //Liga o LED | ||
delay(1000);//espera 1 segundo | ||
digitalWrite(led, LOW); //Desliga o LED | ||
delay(1000); //Espera 1 segundo | ||
|
||
} |
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 |
---|---|---|
|
@@ -9,4 +9,10 @@ Aqui estão dispostos todos os materiais referentes à oficina. Todo o repositó | |
* Desenvolver circuitos virtualmente com um simulador de Arduino; | ||
* Exemplificar algumas aplicações práticas dos exemplos trabalhados na oficina. | ||
|
||
#### Avalie a oficina: | ||
[Clique Aqui](https://docs.google.com/forms/d/e/1FAIpQLScYp2SwS9gSEpAN3QyzDVDtbjIMjgpwcdme4Tk-8DOrlpT45w/viewform) | ||
|
||
#### Projetos no tinkercad: | ||
[Clique Aqui](https://www.tinkercad.com/users/5QDlyI1sotU-leticia-garcez?category=circuits&sort=likes&view_mode=default) | ||
|
||
##### Contato: [email protected] |