Skip to content

Commit 76ecd7e

Browse files
committed
Añadimos ejemplos de Leds WS2812B y Pantalla Display
1 parent eaaa39b commit 76ecd7e

File tree

4 files changed

+161
-1
lines changed

4 files changed

+161
-1
lines changed

CuadernoTecnico/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ __Enlaces.txt__
104104
- **LigthSleep**: Ejemplo de sueño ligero que se activa por tiempo.
105105
- **DeepSleep**: Ejemplo de sueño profundo con activación por tiempo, TOUCH, GPIO
106106
- **EjWS2812B**: Ejemplo de uso de los leds RGB WS2812.
107+
- **EJHCSR04**: Ejemplo de utilización del sensor HC-SR04 para medir distancias a obtaculos.
108+
- **TFTST7735S**: Ejemplo de uso de la pantalla TFT (ST7735)
109+
107110

108111

109112

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* ----------------------------------------------------------------
2+
Fco. Javier Rodriguez Navarro www.pinguytaz.net
3+
4+
5+
Ejemplo Uso del sensor HC-SR04
6+
7+
----------------------------------------------------------------*/
8+
// Definicion de pines
9+
const int Trig = 10 ; // Lanza la señal SALIDA
10+
const int Echo = 9; // Recibe el echo de la señal. ENTRADA
11+
12+
13+
void setup()
14+
{
15+
Serial.begin(9600);
16+
pinMode(Trig,OUTPUT);
17+
pinMode(Echo,INPUT);
18+
digitalWrite(Trig,LOW); // Inicializamos
19+
}
20+
21+
void loop()
22+
{
23+
digitalWrite(Trig, HIGH);//envió del pulso de 10 microsegundos.
24+
delayMicroseconds(10);
25+
digitalWrite(Trig, LOW);//Se espera recibir
26+
27+
28+
// Esperamos que nos llege
29+
long tiempo;
30+
long distancia;
31+
32+
tiempo = pulseIn(Echo, HIGH); //Esperamos y cronometra, 0 es sin respuesta.
33+
distancia = tiempo/ 29 / 2;
34+
35+
Serial.println("Tiempo: "+ String(tiempo) );
36+
Serial.println("Distancia: "+ String(distancia) + " cm");
37+
delay(1000); //Hacemos una pausa de 100ms
38+
39+
}

CuadernoTecnico/Varios/EjWS2812B/EjWS2812B.ino

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
#define TIPO_LED WS2812B // WS2812B
1313
#define ORDEN_COLOR GRB // GRB o RGB
1414
#define NUM_LEDS 4 // Numero de Leds
15+
1516
#define PIN_LED 12 // Pin en el que se conecta la tira.
1617
#define LEDs_SEC 16 // Secuencias
1718

1819
CRGB leds[NUM_LEDS]; // Matriz que permite manipular los LEDs
1920
CRGB secuencias[LEDs_SEC][NUM_LEDS]={
21+
//CRGB secuencias[LEDs_SEC][4]={
2022
CRGB::White,CRGB::Red,CRGB::Green,CRGB::Blue,
2123
CRGB::Red,CRGB::White,CRGB::Green,CRGB::Blue,
2224
CRGB::Red,CRGB::Green,CRGB::White,CRGB::Blue,
@@ -57,7 +59,16 @@ void loop()
5759
for (int i = 0; i<LEDs_SEC; i++)
5860
{
5961
Serial.println("Secuencia "+ String(i));
60-
for (int l=0; l<NUM_LEDS; l++) leds[l]= secuencias[i][l];
62+
for (int l=0; l<NUM_LEDS; l++)
63+
//for (int l=0; l<4; l++)
64+
{
65+
leds[l]= secuencias[i][l];
66+
/*leds[l+4]= secuencias[i][l];
67+
leds[l+8]= secuencias[i][l];
68+
leds[l+12]= secuencias[i][l];
69+
leds[l+16]= secuencias[i][l];
70+
*/
71+
}
6172
FastLED.show();
6273
delay(1000);
6374
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*******************************************************************************************
2+
* Autor: Fco. Javier Rodriguez Navarro
3+
* WEB: www.pinguytaz.net
4+
*
5+
* Descripción: Ejemplo de uso de la pantalla TFT ST7735 mediante SPI.
6+
*
7+
* Libreria: Adafruit-ST7735
8+
***************************************************************************************************/
9+
#include <Adafruit_GFX.h> // Nucleo de la libreria
10+
#include <Adafruit_ST7735.h> // Hardware ST7735
11+
#include <SPI.h> // Comunicacion SPI, por el que se comunica el Display.
12+
13+
14+
#if defined(ESP32) // ESP32
15+
#define TFT_CS 5 // Selector (HSPI_MOSI 15)
16+
#define TFT_MOSI 23 // Datos de salida (HSPI_MOSI 13)
17+
#define TFT_SCLK 18 // Reloj (HSPI_MOSI 14)
18+
19+
#define TFT_RST 2
20+
#define TFT_DC 4
21+
#else // Arduino
22+
#define TFT_CS 10 // Selector
23+
#define TFT_MOSI 11 // Datos de salida
24+
#define TFT_SCLK 13 // Reloj
25+
26+
#define TFT_RST 9
27+
#define TFT_DC 8
28+
29+
#endif
30+
31+
// 1.8" TFT con ST7735:
32+
//Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
33+
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
34+
35+
36+
void setup()
37+
{
38+
#if defined(ESP32)
39+
Serial.begin(115200);
40+
#else
41+
Serial.begin(9600);
42+
#endif
43+
44+
Serial.print(F("Inicio Test ST7735S"));
45+
46+
// Inicializamos la pantalla
47+
tft.initR(INITR_BLACKTAB);
48+
49+
50+
}
51+
52+
void loop()
53+
{
54+
// Uso de TEXTO
55+
tft.fillScreen(ST77XX_BLUE); // Ponemos Fondo Azul y limpiamos pantalla
56+
57+
tft.setRotation(3); // Definimos que se escriba de aabajo arriba
58+
tft.setTextSize(1); // Tamaño del texto de 1-5
59+
tft.setCursor(0,100); // Posicion del Cursor,x,y
60+
tft.setTextColor(ST77XX_GREEN,ST77XX_RED); // Color del texto y fondo
61+
tft.print("Texto de abajo arriba");
62+
63+
tft.setRotation(0); // Define como escribira (0 Normal, 1 90 Grados, 2 180 y 3 270 Grados)
64+
tft.setCursor(0,0); // Posicion del Cursor,x,y
65+
tft.setTextColor(ST77XX_YELLOW); // Color del texto
66+
tft.println("Prueba de ST7735");
67+
tft.setTextColor(ST77XX_RED); // Color del texto
68+
tft.setTextSize(2); // Tamaño del texto de 1-5
69+
tft.println("Otra linea");
70+
tft.setTextSize(1,2); // Tamaño del texto de 1-5 el ancho y el alto
71+
tft.println("Ancho: "+ String(tft.width())); // Da el ancho
72+
tft.println("Alto: "+ String(tft.height())); // Da el alto de la pantalla
73+
74+
delay(10000);
75+
76+
// Dibujo de lineas
77+
tft.fillScreen(ST77XX_RED);
78+
tft.setRotation(0);
79+
tft.setCursor(0,0); // Posicion del Cursor,x,y
80+
tft.setTextSize(3);
81+
tft.setTextColor(ST77XX_YELLOW); // Color del texto
82+
tft.println("Lineas");
83+
84+
tft.drawFastVLine(10,30,66,ST77XX_CYAN); // Horizontal x,y, longitud y color
85+
tft.drawFastHLine(10,30,66,ST77XX_BLUE); // Linea vertical x,y,longitud,color
86+
tft.drawLine(0,0,50,100,ST77XX_MAGENTA); // Linea de x,y a x2,y2 y color
87+
delay(10000);
88+
89+
// Dibujo figuras geometricas
90+
tft.fillScreen(ST77XX_BLACK); // Negro
91+
tft.setRotation(0);
92+
tft.setCursor(0,0); // Posicion del Cursor,x,y
93+
tft.setTextSize(2);
94+
tft.setTextColor(ST77XX_WHITE); // Color del texto
95+
tft.println("Figuras");
96+
97+
tft.drawRect(0,20,50,10,ST77XX_BLUE); // Rectangulo x,y,ancho, alto, color
98+
tft.fillRect(50,20,50,10,ST77XX_BLUE); // Rectangulo relleno
99+
tft.drawRoundRect(0,35,50,10,2,ST77XX_RED); // Esquinas redondeadas x,y,ancho, alto, radio esquinas, color
100+
tft.fillRoundRect(50,35,50,10,15,ST77XX_RED); // Igual pero relleno
101+
tft.drawCircle(15,70,7,ST77XX_GREEN); // Circulo x,y,radio,color
102+
tft.fillCircle(50,70,10,ST77XX_GREEN); // Circulo relleno.
103+
tft.drawTriangle(0,150,50,150,10,90,ST77XX_BLUE); // Triangulo indicando las esquinas y color
104+
tft.fillTriangle(50,150,80,150,10,90,ST77XX_ORANGE); // Triangilño relleno
105+
106+
delay(10000);
107+
}

0 commit comments

Comments
 (0)