Paso 4: Cómo animadas personajes en la pantalla
Animate.c
Esta imagen es bastante aburrida. Pero ver el vídeo más adelante en este post.
ejemplo Animate.c muestra las funciones animateLeft() y animateRight().
Quería darle vida a la tarea de escribir el texto que muestra.
Con hd44780_set_cursorPosition() la función, el incremento/decremento, MoveLeft y MoveRight comandos, puede hacer una animación de texto bastante agradable.
Mirar el código y ver cómo podemos lograr esta tarea.
#include #include "hd44780_4bit_lib.h" #include /* * This code example writes text to the screen using the * Cursor Increment, Decrement and Cursor Left and Right * commands, along with some functions that anaimate the * printing of characters to the display * I was going to use timer events for the character * wait time, but I wanted the code to be non CPU specific. */void main() { WDTCTL = WDTPW | WDTHOLD; // Disable watchdog timer // according to spec give the display 10ms to come up to voltage __delay_cycles(10000 * CPUSPEED); // set up data length, number of lines and font // notice we have setup the display for 2 lines //and using the 5 x 8 character size hd44780_init(N_2LINE, FONT_8); // if needed set up the cursor // hd44780_send_command(HD44780_CMD_DISPLAY_ON_CURSOR); // hd44780_send_command(HD44780_CMD_DISPLAY_ON_CURSOR_BLINK); hd44780_send_command(HD44780_CMD_INCREMENT); hd44780_send_command(HD44780_CMD_MOVE_CURSOR_RIGHT); hd44780_setCursorPosition(0, 0); // The anaimate functions take three parameters: // The text string to print // The visible width of the display in characters // The justification, 'L' for Left justification // 'C' for centered text // 'R' for right jusificatiopn // The number of clock cycles you want to wait after // each character is printed hd44780_animateRight("This is Right", 20, 'C', 2500); hd44780_send_command(HD44780_CMD_DECREMENT); hd44780_send_command(HD44780_CMD_MOVE_CURSOR_LEFT); hd44780_setCursorPosition(1, 19); hd44780_animateLeft("This is Left", 20, 'C', 2500); hd44780_send_command(HD44780_CMD_INCREMENT); hd44780_send_command(HD44780_CMD_MOVE_CURSOR_RIGHT); hd44780_send_command(HD44780_CMD_RETURN_HOME); }
Veamos el código y la revisión sección por sección:
hd44780_setCursorPosition(0, 0); // The anaimate functions take three parameters: // The text string to print // The visible width of the display in characters // The justification, 'L' for Left justification // 'C' for centered text // 'R' for right jusificatiopn // The number of clock cycles you want to wait after // each character is printed hd44780_animateRight("This is Right", 20, 'C', 2500);
Primero ponemos el contador de la dirección de CA se incrementa el texto, luego configuramos la pantalla para mover el cursor a la derecha.
Establecemos la posición del cursor a la fila 0, columna 0.
Entonces llamamos a la función de hd44780_animateRight().
Aviso que tienen que pasar unos argumentos a este método.
El texto que desea imprimir en la pantalla
Ancho visible de la línea en la pantalla, en mi línea de la pantalla uno se divide entre las líneas de dos 20 caracteres en la pantalla.
A continuación especificamos la justificación de texto en la pantalla. 'L' para justificación izquierda, 'C' de centro justificación y 'R' de justificación derecha.
También tienes que entrar en un micro segundo tiempo de pausa, este parámetro especifica el tiempo de pausa después de cada carácter se imprime en la pantalla. Cambiando este parámetro puede acelerar o ralentizar la animación de los personajes que se imprime a la pantalla.
Llamada a la función hd44780_animateRight() entonces imprime la cadena de texto a la pantalla.
hd44780_send_command(HD44780_CMD_DECREMENT); hd44780_send_command(HD44780_CMD_MOVE_CURSOR_LEFT); hd44780_setCursorPosition(1, 19); hd44780_animateLeft("This is Left", 20, 'C', 2500); hd44780_send_command(HD44780_CMD_INCREMENT); hd44780_send_command(HD44780_CMD_MOVE_CURSOR_RIGHT); hd44780_send_command(HD44780_CMD_RETURN_HOME);
Además, luego podemos cambiar la AC, dirección contraria al disminuir la posición del cursor y mueve los caracteres a la izquierda.
Ahora establecemos la posición del cursor a la fila 1 y columna 19, último personaje de la primera línea. Recuerde pantalla está basado en cero. Empezar a contar de 0 en lugar de otro si 1.
Luego llamamos a hd44780_animateLeft() para animar los caracteres a la izquierda.
Codificación de las muestras son sólo un ejemplo básico de lo que puede hacer con la interfaz de controlador hd44780.
Si vengo con más incorporaciones a la biblioteca va agregar cualquiera que todos sepan en un nuevo post.