#include <SPI.h>
#include "Ucglib.h"
Ucglib_ILI9163_18x128x128_HWSPI ucg(/*cd=*/ 5, /*cs=*/ 4, /*reset=*/ 8);
void setup(void)
{
delay(1000);
ucg.begin(UCG_FONT_MODE_SOLID);
ucg.setRotate90();
ucg.setScale2x2();
// Fill the screen with a rainbow color
fillRainbow();
}
int n = 0;
void loop(void)
{
ucg.setFont(ucg_font_logisoso22_tr);
ucg.setPrintPos(0, 30);
// Set text color (e.g., red)
ucg.setColor(255, 0, 0); // RGB values for red
ucg.print("arvind");
// Draw filled circle with rainbow color and reducing radius
drawRainbowCircle();
delay(1000);
n++;
}
// Function to fill the screen with a rainbow color
void fillRainbow() {
int width = ucg.getWidth();
int height = ucg.getHeight();
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
float hue = map(x + y * width, 0, width * height - 1, 0, 255);
uint8_t r, g, b;
HsvToRgb(hue, 255, 255, r, g, b);
ucg.setColor(r, g, b);
ucg.drawBox(x, y, 1, 1);
}
}
}
// Function to draw a filled circle with rainbow color and reducing radius
void drawRainbowCircle() {
int centerX = ucg.getWidth() / 2;
int centerY = ucg.getHeight() / 2;
int maxRadius = min(centerX, centerY);
for (int radius = maxRadius; radius > 0; radius -= 6) {
float hue = map(radius, 0, maxRadius, 0, 255);
uint8_t r, g, b;
HsvToRgb(hue, 255, 255, r, g, b);
ucg.setColor(r, g, b);
ucg.drawDisc(centerX, centerY, radius, UCG_DRAW_ALL);
delay(100); // Adjust delay for animation speed
}
}
// Function to convert HSV to RGB
void HsvToRgb(float h, float s, float v, uint8_t &r, uint8_t &g, uint8_t &b) {
int i = int(h / 60.0) % 6;
float f = h / 60.0 - i;
float p = v * (1.0 - s);
float q = v * (1.0 - f * s);
float t = v * (1.0 - (1.0 - f) * s);
switch (i) {
case 0: r = v * 255; g = t * 255; b = p * 255; break;
case 1: r = q * 255; g = v * 255; b = p * 255; break;
case 2: r = p * 255; g = v * 255; b = t * 255; break;
case 3: r = p * 255; g = q * 255; b = v * 255; break;
case 4: r = t * 255; g = p * 255; b = v * 255; break;
case 5: r = v * 255; g = p * 255; b = q * 255; break;
}
}