Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* TITULO: Como utilizar la pantalla LCD de un NOKIA 5110.
- AUTOR:
- MARIANO DEL CAMPO GARCÍA (@2016) --> INGENIERO TÉCNICO INDUSTRIAL ESPECIALIDAD ELECTRÓNICA
- - FACEBOOK: https://www.facebook.com/mariano.delcampogarcia
- - TWITTER: https://twitter.com/MarianoCampoGa
- - CORREO: [email protected]
- DESCRIPCIÓN DEL PROGRAMA
- Con este programa vamos a ser capaces de visualizar una serie de formas y caracteres, a través
- del LCD de NOKIA 5110, previamente programados mediante las librerías de "Adafruit" (fabricante
- de componentes electrónicos para Arduino).
- ESQUEMA DE CONEXION
- +-----+
- +----[PWR]-------------------| USB |--+
- | +-----+ |
- | GND/RST2 [ ][ ] |
- | MOSI2/SCK2 [ ][ ] A5/SCL[ ] |
- | 5V/MISO2 [ ][ ] A4/SDA[ ] |
- | AREF[ ] |
- | GND[ ] |
- | [ ]N/C SCK/13[ ] |
- | [ ]IOREF MISO/12[ ] | RST del LCD NOKIA 5110 a través de R=10K ohms
- | [ ]RST MOSI/11[ ]~| CE del LCD NOKIA 5110 a través de R=10K ohms
- | [ ]3V3 +---+ 10[ ]~| DC del LCD NOKIA 5110 a través de R=10K ohms
- | [ ]5v -| A |- 9[ ]~| Din del LCD NOKIA 5110 a través de R=10K ohms
- | [ ]GND -| R |- 8[ ] | Clk del LCD NOKIA 5110 a través de R=10K ohms
- | [ ]GND -| D |- |
- | [ ]Vin -| U |- 7[ ] |
- | -| I |- 6[ ]~|
- | [ ]A0 -| N |- 5[ ]~|
- | [ ]A1 -| O |- 4[ ] |
- | [ ]A2 +---+ INT1/3[ ]~|
- | [ ]A3 INT0/2[ ] |
- | [ ]A4/SDA RST SCK MISO TX>1[ ] |
- | [ ]A5/SCL [ ] [ ] [ ] RX<0[ ] |
- | [ ] [ ] [ ] |
- | UNO_R3 GND MOSI 5V ____________/
- \_______________________/
- NOTAS:
- - Conexión de la alimentación del LCD NOKIA 5110:
- - VCC --> +3.3V
- - GND --> GND
- - BL (BackLight) --> +3.3V.
- */
- // Incluimos librerías
- #include <SPI.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_PCD8544.h>
- // Hay que poner una resistencia de 10K ohms en los siguientes pines para limitar el voltaje a 3V
- Adafruit_PCD8544 display = Adafruit_PCD8544(8, 9, 10, 11, 12);
- // Variables del programa
- #define NUMFLAKES 10
- #define XPOS 0
- #define YPOS 1
- #define DELTAY 2
- #define LOGO16_GLCD_HEIGHT 16
- #define LOGO16_GLCD_WIDTH 16
- // Mapa de bits del logo de Adafruit
- static const unsigned char PROGMEM logo16_glcd_bmp[] =
- {
- B00000000, B11000000,
- B00000001, B11000000,
- B00000001, B11000000,
- B00000011, B11100000,
- B11110011, B11100000,
- B11111110, B11111000,
- B01111110, B11111111,
- B00110011, B10011111,
- B00011111, B11111100,
- B00001101, B01110000,
- B00011011, B10100000,
- B00111111, B11100000,
- B00111111, B11110000,
- B01111100, B11110000,
- B01110000, B01110000,
- B00000000, B00110000
- };
- void setup()
- {
- Serial.begin(9600); // Comienzo de la comunicación serie
- display.begin(); // Inicializamos el LCD NOKIA 5110
- display.setContrast(50); // Contraste del LCD NOKIA 5110
- display.display(); // Muestra el logo por pantalla
- delay(2000);
- display.clearDisplay(); // Se borra la pantalla
- // Dibuja un pixel
- display.drawPixel(10, 10, BLACK);
- display.display();
- delay(2000);
- display.clearDisplay();
- // Dibuja líneas
- testdrawline();
- display.display();
- delay(2000);
- display.clearDisplay();
- // Dibuja rectángulos
- testdrawrect();
- display.display();
- delay(2000);
- display.clearDisplay();
- // Dibuja rectángulos rellenos
- testfillrect();
- display.display();
- delay(2000);
- display.clearDisplay();
- // Dibuja círculos
- testdrawcircle();
- display.display();
- delay(2000);
- display.clearDisplay();
- // Dibuja un círculo relleno de 10 px de radio
- display.fillCircle(display.width()/2, display.height()/2, 10, BLACK);
- display.display();
- delay(2000);
- display.clearDisplay();
- // Dibuja rectángulos redondeados
- testdrawroundrect();
- delay(2000);
- display.clearDisplay();
- // Dibuja rectángulos redondeados y rellenos
- testfillroundrect();
- delay(2000);
- display.clearDisplay();
- // Dibuja triángulos
- testdrawtriangle();
- delay(2000);
- display.clearDisplay();
- // Dibuja triángulos rellenos
- testfilltriangle();
- delay(2000);
- display.clearDisplay();
- // Dibuja los primeros 12 caracteres de la fuente
- testdrawchar();
- display.display();
- delay(2000);
- display.clearDisplay();
- // Muestra texto
- display.setTextSize(1);
- display.setTextColor(BLACK);
- display.setCursor(0,0);
- display.println("Hola, mundo!");
- display.setTextColor(WHITE, BLACK);
- display.println(3.141592);
- display.setTextSize(2);
- display.setTextColor(BLACK);
- display.print("0x"); display.println(0xDEADBEEF, HEX);
- display.display();
- delay(2000);
- // Rotación de la pantalla 90º
- display.clearDisplay();
- display.setRotation(1);
- display.setTextSize(1);
- display.setTextColor(BLACK);
- display.setCursor(0,0);
- display.println("Rotacion");
- display.setTextSize(2);
- display.println("Ejemplo!");
- display.display();
- delay(2000);
- // Pantalla sín rotación
- display.setRotation(0);
- // Mapa de bits en miniatura
- display.clearDisplay();
- display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, 1);
- display.display();
- // Invierte la pantalla
- display.invertDisplay(true);
- delay(1000);
- display.invertDisplay(false);
- delay(1000);
- // Dibuja un mapa de bits y anima su movimiento
- testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_WIDTH, LOGO16_GLCD_HEIGHT);
- }
- void loop()
- {
- }
- // Función para dibujar mapas de bits
- void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h)
- {
- uint8_t icons[NUMFLAKES][3];
- randomSeed(666);
- for (uint8_t f=0; f< NUMFLAKES; f++)
- {
- icons[f][XPOS] = random(display.width());
- icons[f][YPOS] = 0;
- icons[f][DELTAY] = random(5) + 1;
- Serial.print("x: ");
- Serial.print(icons[f][XPOS], DEC);
- Serial.print(" y: ");
- Serial.print(icons[f][YPOS], DEC);
- Serial.print(" dy: ");
- Serial.println(icons[f][DELTAY], DEC);
- }
- while (1)
- {
- for (uint8_t f=0; f< NUMFLAKES; f++)
- {
- display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, BLACK);
- }
- display.display();
- delay(200);
- for (uint8_t f=0; f< NUMFLAKES; f++)
- {
- display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, WHITE);
- icons[f][YPOS] += icons[f][DELTAY];
- if (icons[f][YPOS] > display.height())
- {
- icons[f][XPOS] = random(display.width());
- icons[f][YPOS] = 0;
- icons[f][DELTAY] = random(5) + 1;
- }
- }
- }
- }
- // Función para dibujar caracteres
- void testdrawchar(void)
- {
- display.setTextSize(1);
- display.setTextColor(BLACK);
- display.setCursor(0,0);
- for (uint8_t i=0; i < 168; i++)
- {
- if (i == '\n') continue;
- display.write(i);
- }
- display.display();
- }
- // Función para dibujar círculos
- void testdrawcircle(void)
- {
- for (int16_t i=0; i<display.height(); i+=2)
- {
- display.drawCircle(display.width()/2, display.height()/2, i, BLACK);
- display.display();
- }
- }
- // Función para dibujar rectángulos rellenos
- void testfillrect(void)
- {
- uint8_t color = 1;
- for (int16_t i=0; i<display.height()/2; i+=3)
- {
- display.fillRect(i, i, display.width()-i*2, display.height()-i*2, color%2);
- display.display();
- color++;
- }
- }
- // Función para dibujar triángulos
- void testdrawtriangle(void)
- {
- for (int16_t i=0; i<min(display.width(),display.height())/2; i+=5)
- {
- display.drawTriangle(display.width()/2, display.height()/2-i,
- display.width()/2-i, display.height()/2+i,
- display.width()/2+i, display.height()/2+i, BLACK);
- display.display();
- }
- }
- // Función para dibujar triángulos rellenos
- void testfilltriangle(void)
- {
- uint8_t color = BLACK;
- for (int16_t i=min(display.width(),display.height())/2; i>0; i-=5)
- {
- display.fillTriangle(display.width()/2, display.height()/2-i,
- display.width()/2-i, display.height()/2+i,
- display.width()/2+i, display.height()/2+i, color);
- if (color == WHITE) color = BLACK;
- else color = WHITE;
- display.display();
- }
- }
- // Función para dibujar rectángulos redondeados
- void testdrawroundrect(void)
- {
- for (int16_t i=0; i<display.height()/2-2; i+=2)
- {
- display.drawRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, BLACK);
- display.display();
- }
- }
- // Función para dibujar rectángulos redondeados y rellenos
- void testfillroundrect(void)
- {
- uint8_t color = BLACK;
- for (int16_t i=0; i<display.height()/2-2; i+=2)
- {
- display.fillRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, color);
- if (color == WHITE) color = BLACK;
- else color = WHITE;
- display.display();
- }
- }
- // Función para dibujar rectángulos
- void testdrawrect(void)
- {
- for (int16_t i=0; i<display.height()/2; i+=2)
- {
- display.drawRect(i, i, display.width()-2*i, display.height()-2*i, BLACK);
- display.display();
- }
- }
- // Función para dibujar líneas
- void testdrawline()
- {
- for (int16_t i=0; i<display.width(); i+=4)
- {
- display.drawLine(0, 0, i, display.height()-1, BLACK);
- display.display();
- }
- for (int16_t i=0; i<display.height(); i+=4)
- {
- display.drawLine(0, 0, display.width()-1, i, BLACK);
- display.display();
- }
- delay(250);
- display.clearDisplay();
- for (int16_t i=0; i<display.width(); i+=4)
- {
- display.drawLine(0, display.height()-1, i, 0, BLACK);
- display.display();
- }
- for (int8_t i=display.height()-1; i>=0; i-=4)
- {
- display.drawLine(0, display.height()-1, display.width()-1, i, BLACK);
- display.display();
- }
- delay(250);
- display.clearDisplay();
- for (int16_t i=display.width()-1; i>=0; i-=4)
- {
- display.drawLine(display.width()-1, display.height()-1, i, 0, BLACK);
- display.display();
- }
- for (int16_t i=display.height()-1; i>=0; i-=4)
- {
- display.drawLine(display.width()-1, display.height()-1, 0, i, BLACK);
- display.display();
- }
- delay(250);
- display.clearDisplay();
- for (int16_t i=0; i<display.height(); i+=4)
- {
- display.drawLine(display.width()-1, 0, 0, i, BLACK);
- display.display();
- }
- for (int16_t i=0; i<display.width(); i+=4)
- {
- display.drawLine(display.width()-1, 0, i, display.height()-1, BLACK);
- display.display();
- }
- delay(250);
- }
Advertisement
Add Comment
Please, Sign In to add comment