Before I get grilled, this is just something I am playing with. Nothing is specific, and yes, I know the code needs to be cleaned up and spacing fixed. But is working fine. Right now, it helps me keep track of what I am doing.
I am still learning and I am doing this as I experiment.
I am using an Arduino Nano with a 1.8 TFT LCD display with SD (though not hooked up at the moment)
My question is, can I, and, how do I change part of the graphic to a new graphic when I pressing a button? I know how to implement the button code, and I know how to create the graphic. I also know how to basically overly a new graphic on top of another.
What I don't quite understand completely is, how to implement the code to use a button to start that new graphic.
What I would like to be able to do, is push the button, or maybe even two different ones, to switch to a new graphic/animation. One of which could clear the entire screen perhaps, while to other just does a localized section on the screen.
Most of the graphics were put before the loop so that they would not be overwritten by the animated pulse circles.
Originally I had the gradient bars cycle through colors but it was slowing everything down and kept flashing the screen, so they are now static so to speak.
Hope what I am asking makes sense.
If anyone be so kind as to perhaps help, I would appreciate it.
#include "Ucglib.h"
// Create display and define the pins:
Ucglib_ST7735_18x128x160_HWSPI ucg(8, 10, 9); // (A0=8, CS=10, RESET=9)
int Variable1; // Create a variable to have something dynamic to show on the display
uint8_t z = 80; // start value
uint32_t lcg_rnd(void) {
z = (uint8_t)((uint16_t)65*(uint16_t)z + (uint16_t)17);
return (uint32_t)z;
}
void setup(void) // Start of setup
{
// Display setup:
ucg.begin(UCG_FONT_MODE_SOLID); // It writes a background for the text. This is the recommended option
ucg.clearScreen(); // Clear the screen
// Set display orientation:
ucg.setRotate90(); // Put 90, 180 or 270, or comment to leave default
ucg.setFont(ucg_font_helvB08_tr);
//*************************************
// Draw filled rounded rectangle: top left corner
ucg.setColor(255, 128, 64); // Set color (0,R,G,B)
ucg.drawRBox(0, 0, 50, 40, 12); // Start from top-left pixel (x,y,wigth,height,radius)
// Draw filled rounded rectangle: black fill
ucg.setColor(0, 0, 0); // Set color (0,R,G,B)
ucg.drawRBox(20, 8, 120, 40, 8); // Start from top-left pixel (x,y,wigth,height,radius)
// Write to the display the text "Scan":
ucg.setFont(ucg_font_helvB08_tr); // Set font
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(125,20); // Set position (x,y)
ucg.print("SCAN"); // Print text or value
// Draw filled rectangle: blip in front of text
ucg.setColor(164, 128, 255); // Set color (0,R,G,B)
ucg.drawBox(30, 25, 5, 5); // Start from top-left pixel (x,y,wigth,height)
// Write to the display the text:
ucg.setFont(ucg_font_profont10_mr); // Set font
ucg.setColor(0, 255, 128, 0); // Set color (0,R,G,B)
ucg.setPrintPos(39,30); // Set position (x,y)
ucg.print("SPECTRUM"); // Print text or value
// Draw filled rectangle: 2nd blip in front of 2nd text
ucg.setColor(164, 128, 255); // Set color (0,R,G,B)
ucg.drawBox(90, 25, 5, 5); // Start from top-left pixel (x,y,wigth,height)
// Write to the display the 2nd text:
ucg.setFont(ucg_font_profont10_mr); // Set font
ucg.setColor(0, 128, 128, 255); // Set color (0,R,G,B)
ucg.setPrintPos(99,30); // Set position (x,y)
ucg.print("SEARCH"); // Print text or value
// Draw filled rectangle: blip in front of text
ucg.setColor(164, 128, 255); // Set color (0,R,G,B)
ucg.drawBox(30, 35, 5, 5); // Start from top-left pixel (x,y,wigth,height)
// Write to the display the text:
ucg.setFont(ucg_font_profont10_mr); // Set font
ucg.setColor(0, 255, 128, 255); // Set color (0,R,G,B)
ucg.setPrintPos(39,40); // Set position (x,y)
ucg.print("ANALYZE"); // Print text or value
// Draw filled rectangle: fill gap next to top
ucg.setColor(0, 0, 0); // Set color (0,R,G,B)
ucg.drawBox(38, 0, 5, 15); // Start from top-left pixel (x,y,wigth,height)
// Draw filled rectangle: orange bar top
ucg.setColor(255, 160, 0); // Set color (0,R,G,B)
ucg.drawBox(42, 0, 120, 8); // Start from top-left pixel (x,y,wigth,height)
// Draw filled rectangle: left gap below top
ucg.setColor(0, 0, 0); // Set color (0,R,G,B)
ucg.drawBox(0, 30, 25, 10); // Start from top-left pixel (x,y,wigth,height)
// Draw filled rectangle:left grayish rectangle below gap
ucg.setColor(200, 128, 96); // Set color (0,R,G,B)
ucg.drawBox(0, 33, 20, 20); // Start from top-left pixel (x,y,wigth,height)
// Draw filled rectangle:left below grayish rectangle gap
ucg.setColor(0, 0, 0); // Set color (0,R,G,B)
ucg.drawBox(0, 50, 20, 10); // Start from top-left pixel (x,y,wigth,height)
// Draw filled rectangle:left orange rectangle middle
ucg.setColor(255, 150, 0); // Set color (0,R,G,B)
ucg.drawBox(0, 53, 20, 60); // Start from top-left pixel (x,y,wigth,height)
// Draw filled rectangle:left bottom orange rectangle
ucg.setColor(255, 160, 0); // Set color (0,R,G,B)
ucg.drawBox(-1, 115, 21, 40); // Start from top-left pixel (x,y,wigth,height)
// Draw rectangle:
ucg.setColor(122, 122, 122); // Set color (0,R,G,B)
ucg.drawFrame(30, 60, 120, 65); // Start from top-left pixel (x,y,wigth,height)
// Draw rounded rectangle:
//ucg.setColor(0, 255, 255); // Set color (0,R,G,B)
//ucg.drawRFrame(30, 60, 115, 65, 8); // Start from top-left pixel (x,y,wigth,height,radius)
//Big color gradient radar box
ucg.setColor(0, 0, 20, 80);
ucg.setColor(1, 85, 95, 115);
ucg.setColor(2, 60, 0, 40);
ucg.setColor(3, 98, 98, 98);
ucg.drawGradientBox(31, 61, 118, 62);
// Draw circle:
//ucg.setColor(255, 255, 0); // Set color (0,R,G,B)
//ucg.drawCircle(110, 74, 6, UCG_DRAW_ALL); // (x,y,radius,option)
// Draw filled triangle:
ucg.setColor(122, 122, 122); // Set color (0,R,G,B)
ucg.drawTriangle(50,87, 100,70, 95,100); // (x0,y0,x1,y1,x2,y2)
// Draw filled circle:
ucg.setColor(0, 255, 0, 0); // Set color (0,R,G,B)
ucg.drawDisc(42, 86, 2, UCG_DRAW_ALL); // (x,y,radius,option)
ucg.setColor(0, 255, 0, 0); // Set color (0,R,G,B)
ucg.drawDisc(47, 94, 2, UCG_DRAW_ALL); // (x,y,radius,option)
ucg.setColor(0, 230, 130, 100); // Set color (0,R,G,B
ucg.drawLine(31, 80, 148, 80); //horizontal line
ucg.drawLine(31, 105, 148, 105);//horizontal line
ucg.drawVLine(60, 61, 64); //vertical line
ucg.drawVLine(90, 61, 64); //vertical line
ucg.drawVLine(120, 61, 64); //vertical line
ucg.setFontMode(UCG_FONT_MODE_TRANSPARENT);
ucg.setColor(0, 255, 35, 35);
ucg.setPrintDir(0);
ucg.setPrintPos(100,120);
ucg.print("DETECTING");
ucg.setFontMode(UCG_FONT_MODE_SOLID);
} // End of setup
void draw_gradient_box2(void){
//First color gradient bar
ucg.setColor(0, 0, 20, 80);
ucg.setColor(1, 66, 66, 15);
ucg.setColor(2, 60, 0, 40);
ucg.setColor(3, 0, 160, 160);
ucg.drawGradientBox(30, 44, 55, 8);
}
void draw_gradient_box3(void){
//First color gradient bar
ucg.setColor(0, 170, 220, 255);
ucg.setColor(1, 64, 0, 64);
ucg.setColor(2, 70, 220, 255);
ucg.setColor(3, 64, 0, 64);
ucg.drawGradientBox(90, 44, 55, 8);
}
void gradient_circle(void)
{
ucg_int_t mx;
ucg_int_t x, xx;
mx = ucg.getWidth() / 3;
//my = ucg.getHeight() / 2;
for( x = 0; x < mx; x++ )
{
xx = (((uint16_t)x)*255)/mx;
ucg.setColor(184, 128-xx/2, 255-xx);
ucg.drawCircle(110, 85, 4, UCG_DRAW_ALL);
//ucg.setColor(196, 128-xx/2, 128-xx);
ucg.drawCircle(110, 85, 10, UCG_DRAW_ALL);
//ucg.setColor(164, 164-xx/2, 255-xx);
ucg.drawCircle(110, 85, 16, UCG_DRAW_ALL);
}
}
void gradient_circle2(void)
{
ucg_int_t mx;
ucg_int_t x, xx;
mx = ucg.getWidth() / 3;
//my = ucg.getHeight() / 2;
for( x = 0; x < mx; x++ )
{
xx = (((uint16_t)x)*255)/mx;
ucg.setColor(255, 128-xx/2, 255-xx);
ucg.drawCircle(90, 95, 4, UCG_DRAW_ALL);
//ucg.setColor(196, 128-xx/2, 128-xx);
ucg.drawCircle(90, 95, 10, UCG_DRAW_ALL);
//ucg.setColor(164, 164-xx/2, 255-xx);
ucg.drawCircle(90, 95, 16, UCG_DRAW_ALL);
}
}
void loop(void) // Start of loop
{
draw_gradient_box3();
draw_gradient_box2();
gradient_circle();
gradient_circle2();
} // End of loop