-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
374 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
...s/ativar_led_RGB_com_potenciometro_e_botoes/ativar_led_RGB_com_potenciometro_e_botoes.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,46 @@ | ||
/********************************-****************** | ||
Controle a cor de um LED RGB através de botões e | ||
um potenciômetro. | ||
Desenvolvido por Letícia P Garcez - 03/2024 | ||
****************************************************/ | ||
|
||
#include <laboratorioFW-DIY.h> | ||
|
||
#define btn1 B_0 | ||
#define btn2 B_1 | ||
#define btn3 B_2 | ||
#define pot S_0 | ||
#define r L_4 | ||
#define g L_5 | ||
#define b L_6 | ||
|
||
void setup() { | ||
pinMode(btn1, INPUT); | ||
pinMode(btn2, INPUT); | ||
pinMode(btn3, INPUT); | ||
pinMode(pot, INPUT); | ||
pinMode(r, OUTPUT); | ||
pinMode(g, OUTPUT); | ||
pinMode(b, OUTPUT); | ||
analogWrite(g, 0); | ||
analogWrite(b, 0); | ||
analogWrite(r, 0); | ||
} | ||
|
||
void loop() { | ||
int leitura = analogRead(pot); | ||
|
||
int leituraMapeada = map(leitura, 0, 8191, 0, 255); | ||
|
||
if (digitalRead(btn1)) { | ||
analogWrite(r, leituraMapeada); | ||
} else if (digitalRead(btn2)) { | ||
analogWrite(g, leituraMapeada); | ||
} else if (digitalRead(btn3)) { | ||
analogWrite(b, leituraMapeada); | ||
} | ||
|
||
|
||
delay(300); | ||
} |
43 changes: 43 additions & 0 deletions
43
examples/ativar_servo_motor_com_botoes/ativar_servo_motor_com_botoes.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,43 @@ | ||
/********************************-****************** | ||
Aperte os botões para ver o servo motor se mover em | ||
direções diferentes. | ||
Desenvolvido por Letícia P Garcez - 03/2024 | ||
****************************************************/ | ||
|
||
#include <ESP32_ISR_Servo.h> | ||
#include <laboratorioFW-DIY.h> | ||
|
||
#define motor M_0 | ||
#define btnEsquerda B_1 | ||
#define btnDireita B_3 | ||
|
||
#define MIN_MICROS 800 //544 | ||
#define MAX_MICROS 2450 | ||
|
||
int escreveEAtualiza(int angulo, int incremento); | ||
|
||
int meuServo = ESP32_ISR_Servos.setupServo(motor, MIN_MICROS, MAX_MICROS); | ||
|
||
int angulo = 0; | ||
|
||
void setup() { | ||
pinMode(btnEsquerda, INPUT); | ||
pinMode(btnDireita, INPUT); | ||
} | ||
|
||
void loop() { | ||
|
||
if (digitalRead(btnEsquerda)) { | ||
angulo = escreveEAtualiza(angulo, 10); | ||
} else if (digitalRead(btnDireita)) { | ||
angulo = escreveEAtualiza(angulo, -10); | ||
} | ||
delay(50); | ||
} | ||
|
||
int escreveEAtualiza(int angulo, int incremento) { | ||
int novoAngulo = angulo + incremento; | ||
ESP32_ISR_Servos.setPosition(meuServo, novoAngulo); | ||
return novoAngulo % 180; | ||
} |
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 @@ | ||
/********************************-****************** | ||
Exemplo Blink adaptado para a biblioteca | ||
Desenvolvido por Letícia P Garcez - 03/2024 | ||
****************************************************/ | ||
#include <laborarotioFW-DIY.h> | ||
|
||
#define led L_1 | ||
|
||
void setup(){ | ||
pinMode(led,OUTPUT); | ||
} | ||
|
||
void loop{ | ||
digitalWrite(led,HIGH); | ||
delay(1000); | ||
digitalWrite(led,LOW); | ||
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,23 @@ | ||
/********************************-****************** | ||
Altere a luminosidade de um LED utilizando o sensor | ||
LDR. Um botão pode ser apertado para inverter a | ||
lógica de escrita no LED. | ||
Desenvolvido por Letícia P Garcez - 03/2024 | ||
****************************************************/ | ||
|
||
#include <laboratorioFW.h> | ||
|
||
#define ldr S_2 | ||
#define led L_0 | ||
|
||
void setup() { | ||
pinMode(ldr, INPUT); | ||
pinMode(led, OUTPUT); | ||
} | ||
|
||
void loop() { | ||
int leituraMapeada = map(analogRead(ldr), 0, 8191, 0, 255); | ||
analogWrite(led, 255 - leituraMapeada); | ||
delay(100); | ||
} |
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,82 @@ | ||
/********************************-****************** | ||
Aperte um botão para tocar a música dó ré mi fá. | ||
Desenvolvido por Letícia P Garcez - 03/2024 | ||
****************************************************/ | ||
|
||
#include <laboratorioFW-DIY.h> | ||
|
||
#define ledR L_4 | ||
#define ledG L_5 | ||
#define ledB L_6 | ||
#define buzzer P_0 | ||
#define btn B_1 | ||
|
||
#define NOTE_C7 2093 | ||
#define NOTE_D7 2349 | ||
#define NOTE_E7 2637 | ||
#define NOTE_F7 2794 | ||
#define NOTE_G7 3136 | ||
|
||
|
||
void ligaLED(int r, int g, int b); | ||
|
||
void setup() { | ||
pinMode(buzzer, OUTPUT); | ||
pinMode(btn, INPUT); | ||
pinMode(ledR, INPUT); | ||
pinMode(ledG, INPUT); | ||
pinMode(ledB, INPUT); | ||
ligaLED(0, 0, 0); | ||
} | ||
|
||
const int tamanho = 32; | ||
|
||
int notas[tamanho] = {NOTE_C7, NOTE_D7, NOTE_E7, NOTE_F7, 0, NOTE_F7, NOTE_F7, 0, | ||
NOTE_C7, NOTE_D7, NOTE_C7, NOTE_D7, 0, NOTE_D7, NOTE_D7, 0, | ||
NOTE_C7, NOTE_G7, NOTE_F7, NOTE_E7, 0, NOTE_E7, NOTE_E7, 0, | ||
NOTE_C7, NOTE_D7, NOTE_E7, NOTE_F7, 0, NOTE_F7, NOTE_F7, 0 | ||
}; | ||
|
||
int duracao[tamanho] = {400, 400, 400, 400, 200, 300, 300, 200, | ||
400, 400, 400, 400, 200, 300, 300, 200, | ||
400, 400, 400, 400, 200, 300, 300, 200, | ||
400, 400, 400, 400, 200, 300, 300, 200 | ||
}; | ||
|
||
void loop() { | ||
if (digitalRead(btn)) { | ||
for (int c = 0; c < tamanho; c++) { | ||
int nota = notas[c]; | ||
tone(buzzer, nota); | ||
switch (nota) { | ||
case NOTE_C7: | ||
ligaLED(154, 200, 100); | ||
break; | ||
case NOTE_D7: | ||
ligaLED(0, 200, 0); | ||
break; | ||
case NOTE_E7: | ||
ligaLED(150, 50, 80); | ||
break; | ||
case NOTE_F7: | ||
ligaLED(0, 84, 100); | ||
break; | ||
case NOTE_G7: | ||
ligaLED(30, 30, 200); | ||
break; | ||
} | ||
delay(duracao[c]); | ||
ligaLED(0, 0, 0); | ||
} | ||
} | ||
else { | ||
noTone(buzzer);//garante que o buzzer não vai receber nenhum lixo | ||
} | ||
} | ||
|
||
void ligaLED(int r, int g, int b) { | ||
analogWrite(ledR,r); | ||
analogWrite(ledG,g); | ||
analogWrite(ledB,b); | ||
} |
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,134 @@ | ||
/********************************-****************** | ||
Jogo Gênio: um jogo da memória onde você deve | ||
repetir a sequência em que luzes acendem. | ||
Desenvolvido por Letícia P Garcez - 03/2024 | ||
****************************************************/ | ||
|
||
#include <laboratorioFW-DIY.h> | ||
|
||
#define led1 L_0 | ||
#define led2 L_1 | ||
#define led3 L_2 | ||
#define led4 L_3 | ||
#define btn1 B_0 | ||
#define btn2 B_1 | ||
#define btn3 B_2 | ||
#define btn4 B_3 | ||
#define buzzer P_0 | ||
|
||
//sons | ||
#define S1 1047 | ||
#define S2 1175 | ||
#define S3 1319 | ||
#define S4 1397 | ||
#define SE 2093 | ||
|
||
int posicoes; | ||
int sequencia[30]; | ||
|
||
void adicionaNaSequencia(void); | ||
void acendeLed(int n); | ||
void tocaSequencia(void); | ||
void confereSequencia(void); | ||
void tocaErrado(void); | ||
|
||
void setup() { | ||
pinMode(led1, OUTPUT); | ||
pinMode(led2, OUTPUT); | ||
pinMode(led3, OUTPUT); | ||
pinMode(led4, OUTPUT); | ||
pinMode(btn1, INPUT); | ||
pinMode(btn2, INPUT); | ||
pinMode(btn3, INPUT); | ||
pinMode(btn4, INPUT); | ||
pinMode(buzzer, OUTPUT); | ||
} | ||
|
||
void loop() { | ||
adicionaNaSequencia(); | ||
delay(700); | ||
confere(); | ||
delay(800); | ||
} | ||
|
||
void adicionaNaSequencia(void) { | ||
if (posicoes != 0) { | ||
tocaSequencia(); | ||
} | ||
randomSeed(millis());//A seed do random vira o tempo atual de execução, o que faz com que as sequencias possam ser diferentes | ||
sequencia[posicoes] = random(1, 5); //Gera um random entre 1 e 4 | ||
acendeLed(sequencia[posicoes]); | ||
posicoes++; | ||
|
||
} | ||
|
||
void acendeLed (int n) { | ||
//Os valores 1,2,3,4 são associados ás saídas. | ||
switch (n) { | ||
case 1: | ||
digitalWrite(led1, HIGH); | ||
tone(buzzer, S1); | ||
delay(500); | ||
noTone(buzzer); | ||
digitalWrite(led1, LOW); | ||
break; | ||
case 2: | ||
digitalWrite(led2, HIGH); | ||
tone(buzzer, S2); | ||
delay(500); | ||
digitalWrite(led2, LOW); | ||
noTone(buzzer); | ||
break; | ||
case 3: | ||
digitalWrite(led3, HIGH); | ||
tone(buzzer, S3); | ||
delay(500); | ||
digitalWrite(led3, LOW); | ||
noTone(buzzer); | ||
break; | ||
case 4: | ||
digitalWrite(led4, HIGH); | ||
tone(buzzer, S4); | ||
delay(500); | ||
noTone(buzzer); | ||
digitalWrite(led4, LOW); | ||
} | ||
} | ||
|
||
void tocaSequencia(void) { | ||
for (int i = 0; i < posicoes; i++) { | ||
acendeLed(sequencia[i]); | ||
delay(500); | ||
} | ||
} | ||
|
||
void confere(void) { | ||
int i = 0; | ||
while (i < posicoes) { | ||
bool estaCorreto = (digitalRead(btn1) && sequencia[i] == 1) || (digitalRead(btn2) && sequencia[i] == 2) || (digitalRead(btn3) && sequencia[i] == 3) || (digitalRead(btn4) && sequencia[i] == 4); | ||
bool estaIncorreto = (digitalRead(btn1) && sequencia[i] != 1) || (digitalRead(btn2) && sequencia[i] != 2) || (digitalRead(btn3) && sequencia[i] != 3) || (digitalRead(btn4) && sequencia[i] != 4); | ||
if (estaCorreto) { | ||
acendeLed(sequencia[i]); | ||
i++; | ||
} | ||
else if (estaIncorreto) { | ||
tocaErrado(); | ||
} | ||
} | ||
} | ||
|
||
void tocaErrado (void) { | ||
digitalWrite(led1, HIGH); | ||
digitalWrite(led2, HIGH); | ||
digitalWrite(led3, HIGH); | ||
digitalWrite(led4, HIGH); | ||
tone(buzzer, SE); | ||
delay(1500); | ||
noTone(buzzer); | ||
digitalWrite(led1, LOW); | ||
digitalWrite(led2, LOW); | ||
digitalWrite(led3, LOW); | ||
digitalWrite(led4, LOW); | ||
posicoes = 0; | ||
} |
27 changes: 27 additions & 0 deletions
27
examples/leitura_sensores_externos/leitura_sensores_externos.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,27 @@ | ||
/********************************-****************** | ||
Leitura dos sensores externos conectados através | ||
dos headers. | ||
Desenvolvido por Letícia P Garcez - 03/2024 | ||
****************************************************/ | ||
|
||
#include <laboratorioFW-DIY.h> | ||
|
||
#define analogico E_2 | ||
#define digital E_3 | ||
|
||
|
||
void setup() { | ||
pinMode(analogico, INPUT); | ||
pinMode(digital, INPUT); | ||
Serial.begin(19200); | ||
} | ||
|
||
|
||
void loop() { | ||
Serial.print("Digital - "); | ||
Serial.print(digitalRead(digital)); | ||
Serial.print(" Analogico - "); | ||
Serial.println(analogRead(analogico)); | ||
delay(1000); | ||
} |