I'm currently using the ucglib library. I'm new to arduino and I'm wanting to simply display a lcd smiley I made with the byte generator. I still have some of the original 'font hello world' stuff down the bottom but I'm curious how to make my character work.
I want to make different smileys in different colours but I'm unsure how to go about this as every guide is on a 16x2 lcd and not a tft one. I have an arduino nano that is just hooked up to that lcd display. I'm going to make pressing buttons change the smiley after I've figured out how to actually put a smiley into it. Hope someone can help.
* LED = 3.3V
* SCK = 13
* SDA = 11
* A0 = 8
* RESET = 9
* CS = 10
* GND = GND
* VCC = 5V
#include "Ucglib.h" // Include Ucglib library to drive the display
// Create display and define the pins:
Ucglib_ST7735_18x128x160_HWSPI ucg(8, 10, 9);
int smiley = byte customChar[] = {
B00000,
B01010,
B01010,
B00000,
B10001,
B10001,
B11111,
B00000
};
void setup(void) // Start of setup
{
//ucg.begin(UCG_FONT_MODE_TRANSPARENT); // It doesn't overwrite background, so it's a mess for text that changes
ucg.begin(UCG_FONT_MODE_SOLID); // It writes a background for the text. This is the recommended option
ucg.clearScreen(); // Clear the screen
ucg.setRotate180(); // Put 90, 180 or 270, or comment to leave default
ucg.setColor(0, 255, 255, 255); // Set color (0,R,G,B)
ucg.setColor(1, 0, 0, 0); // Set color of text background (1,R,G,B)
ucg.setPrintPos(0,24); // Set position (x,y)
ucg.print("Welcome"); // Print text or value
// Draw smiley:
ucg.setColor(0, 255, 255); // Set color (0,R,G,B)
ucg.drawFrame(0, 58, 60, 30); // Start from top-left pixel (x,y,wigth,height)
void loop(void) // Start of loop
{
Variable1++; // Increase variable by 1
if(Variable1 > 150) // If Variable1 is greater than 150
{
Variable1 = 0; // Set Variable1 to 0
}
// Convert Variable1 into a string, so we can change the text alignment to the right:
// It can be also used to add or remove decimal numbers.
char string[10]; // Create a character array of 10 characters
// Convert float to a string:
dtostrf(Variable1, 3, 0, string); // (<variable>,<amount of digits we are going to use>,<amount of decimal digits>,<string name>)
// We are going to print on the display everything that is dynamic on the loop, to refresh continuously:
// Write to the display the Variable1 with left text alignment:
ucg.setFont(ucg_font_inb16_mr); // Set font
ucg.setColor(0, 255, 255, 0); // Set color (0,R,G,B)
ucg.setColor(1, 0, 0, 0); // Set color of text background (1,R,G,B)
ucg.setPrintPos(9,81); // Set position (x,y)
ucg.print(Variable1); // Print text or value
// There is a problem when we go, for example, from 100 to 99 because it doesn't automatically write a background on
// the last digit we are not longer refreshing. We need to check how many digits are and fill the space remaining.
if(Variable1 < 10) // If Variable1 is less than 10...
{
// Fill the other digit with background color:
ucg.print(" ");
}
if(Variable1 < 100) // If Variable1 is less than 100...
{
// Fill the other digit with background color:
ucg.print(" ");
}
// Write to the display the string with right text alignment:
ucg.setFont(ucg_font_inb16_mr); // Set font
ucg.setColor(0, 0, 255, 0); // Set color (0,R,G,B)
ucg.setColor(1, 0, 0, 0); // Set color of text background (1,R,G,B)
ucg.setPrintPos(76,81); // Set position (x,y)
ucg.print(string); // Print text or value
} // End of loop