#include <Arduino.h>
#include <U8g2lib.h>
#include "RTClib.h"
RTC_DS1307 rtc;
U8G2_MAX7219_32X8_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 11, /* data=*/ 12, /* cs=*/ 10, /* dc=*/ U8X8_PIN_NONE, /* reset=*/ U8X8_PIN_NONE);
char time_string[10]; // string to hold the current time to be displayed
class Budzik {
public:
int godzina;
int minuta;
bool aktywny;
Budzik() {
godzina = 0;
minuta = 0;
aktywny = false;
}
};
Budzik budziki[10];
void showtrue() {
char* jeden[11] = {"Kocham cie", "Jestes wspaniala", "Jak tam dzionek", "Dasz rade", "Wierze w ciebie", "Jadlas cos?",
"Pamietaj o odpoczynku", "Jestes moim skarbem", "Moze kawka?", "Jestes moim idealem", "Pamietaj o mnie :*"};
char* dwa[11] = {"Kochanie", "Slonce", "Sloneczko", "Skarbie", "Miska", "Niunia", "Kotku", "Krowko", "Zabko", "Myszko", "Serduszko"};
int ranj = random(0, 11);
delay(100);
int rand = random(0, 11);
char zdanie[50]; // Przyjmujemy maksymalną długość zdania na 50 znaków, dostosuj ją do swoich potrzeb
strcpy(zdanie, jeden[ranj]);
strcat(zdanie, " ");
strcat(zdanie, dwa[rand]);
int zdanieLength = strlen(zdanie); // Oblicz długość zdania
u8g2.setFont(u8g2_font_amstrad_cpc_extended_8f);
for (int i = 0; i < zdanieLength * 8; i++) {
u8g2.clearBuffer();
u8g2.drawStr(-i, 8, zdanie);
u8g2.sendBuffer();
delay(150);
}
}
void aktywujBudzik(){
boolean aktywuj = true;
while(aktywuj){
if(analogRead(A2)>999){
u8g2.setFont(u8g2_font_amstrad_cpc_extended_8f);
for(int i = 0;i<68;i++){
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(-i, 8, "Cofnij Menu"); // draw the time string to the display
u8g2.sendBuffer(); // transfer internal memory to the display
byte buttonValue = digitalRead(6);
if (buttonValue == LOW) {
tone(8, 262, 50);
while(buttonValue == LOW){
buttonValue = digitalRead(6);
}
aktywuj=false;
}
if(!aktywuj || analogRead(A2)<1000) i=1000;
else delay(100);
}
}
else{
int indeks = round(analogRead(A2) / 100);
if (budziki[indeks].aktywny) {
sprintf(time_string, "%02d:%02d", budziki[indeks].godzina, budziki[indeks].minuta);
u8g2.setFont(u8g2_font_t0_11b_tn);
u8g2.clearBuffer();
u8g2.drawStr(2, 8, time_string);
u8g2.sendBuffer();
delay(100);
} else {
sprintf(time_string, "%02d:%02d", budziki[indeks].godzina, budziki[indeks].minuta);
u8g2.setFont(u8g2_font_t0_11b_tn);
u8g2.clearBuffer();
u8g2.drawStr(2, 8, time_string);
for(int i=0;i<32;i++)u8g2.drawPixel(i,4);
u8g2.sendBuffer();
delay(100);
}
byte buttonValue = digitalRead(6);
if (buttonValue == LOW) {
tone(8, 262, 50);
budziki[indeks].aktywny=!budziki[indeks].aktywny;
while(buttonValue == LOW){
buttonValue = digitalRead(6);
}
}
}
}
}
void edytujBudziki(){
boolean aktywuj = true;
while(aktywuj){
if(analogRead(A2)>999){
u8g2.setFont(u8g2_font_amstrad_cpc_extended_8f);
for(int i = 0;i<68;i++){
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(-i, 8, "Cofnij Menu"); // draw the time string to the display
u8g2.sendBuffer(); // transfer internal memory to the display
byte buttonValue = digitalRead(6);
if (buttonValue == LOW) {
tone(8, 262, 50);
while(buttonValue == LOW){
buttonValue = digitalRead(6);
}
aktywuj=false;
}
if(!aktywuj || analogRead(A2)<1000) i=1000;
else delay(100);
}
}
else{
int indeks = round(analogRead(A2) / 100);
sprintf(time_string, "%02d:%02d", budziki[indeks].godzina, budziki[indeks].minuta);
u8g2.setFont(u8g2_font_t0_11b_tn);
u8g2.clearBuffer();
u8g2.drawStr(2, 8, time_string);
u8g2.sendBuffer();
byte buttonValue = digitalRead(6);
if (buttonValue == LOW) {
tone(8, 262, 50);
while(buttonValue == LOW){
buttonValue = digitalRead(6);
}
edytujBudzik(indeks);
}
delay(100);
}
}
}
void edytujBudzik(int indeks){
int godzina;
int minuta;
byte buttonValue = digitalRead(6);
while(buttonValue == HIGH){
godzina = round(analogRead(A2) / 43);
sprintf(time_string, "%02dh", godzina);
u8g2.setFont(u8g2_font_amstrad_cpc_extended_8f);
u8g2.clearBuffer();
u8g2.drawStr(2, 8, time_string);
u8g2.sendBuffer();
buttonValue = digitalRead(6);
delay(10);
}
tone(8, 262, 50);
buttonValue = digitalRead(6);
while(buttonValue == LOW){
buttonValue = digitalRead(6);
delay(10);
}
buttonValue = digitalRead(6);
while(buttonValue == HIGH){
minuta = round(analogRead(A2) / 17);
if(minuta==60)minuta=minuta-1;
sprintf(time_string, "%02dm", minuta);
u8g2.setFont(u8g2_font_amstrad_cpc_extended_8f);
u8g2.clearBuffer();
u8g2.drawStr(2, 8, time_string);
u8g2.sendBuffer();
buttonValue = digitalRead(6);
delay(10);
}
tone(8, 262, 50);
buttonValue = digitalRead(6);
while(buttonValue == LOW){
buttonValue = digitalRead(6);
delay(10);
}
budziki[indeks].godzina=godzina;
budziki[indeks].minuta=minuta;
budziki[indeks].aktywny=true;
}
void graLot(){
int board[8][32];
int enemyx[6];
int enemyy[6];
int points=0;
int startValue = 6;
for (int i = 0; i < 6; i++) {
enemyx[i] = startValue + i * 5;
}
for (int i = 0; i < 6; i++) {
enemyy[i] = random(0, 7); // Losowanie wartości od 0 do 6
}
bool game=true;
while(game){
int player = round(analogRead(A2) / 127);
if(player>7)player--;
for (int i = 0; i < 6; i++) {
if (enemyx[i] < 0) {
enemyx[i] = 31; // Przesunięcie w lewo
enemyy[i] = random(0, 7); // Losowanie nowego y
} else if (enemyx[i] == 0 || enemyx[i] == 1) {
if (enemyy[i] == player || enemyy[i] + 1 == player ){
game=false;
tone(8, 208, 500);
delay(500);
tone(8, 196, 500);
delay(500);
tone(8, 185, 1000);
delay(1000);
}
else{
if (enemyx[i] == 0){
tone(8, 392, 100);
points++;
}
}
}
}
if(game){
for(int y=0;y<7;y++){
for(int x=0;x<32;x++){
u8g2.clearBuffer();
u8g2.drawPixel(0,player);
u8g2.drawPixel(1,player);
for(int i=0;i<6;i++){
u8g2.drawPixel(enemyx[i],enemyy[i]);
u8g2.drawPixel(enemyx[i],enemyy[i]+1);
}
u8g2.sendBuffer();
}
}
for (int i = 0; i < 6; i++) {
enemyx[i]--;
}
delay(5);
}
}
sprintf(time_string, "%4d", points); // add hours, colon symbol and minutes into a string
u8g2.setFont(u8g2_font_t0_11b_tn); // choose a suitable font
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(2, 8, time_string); // draw the time string to the display
u8g2.sendBuffer(); // transfer internal memory to the display
byte buttonValue = digitalRead(6);
while(buttonValue == HIGH){
buttonValue = digitalRead(6);
delay(10);
}
tone(8, 262, 50);
while(buttonValue == LOW){
buttonValue = digitalRead(6);
delay(10);
}
}
void stoLat(){
u8g2.setFont(u8g2_font_amstrad_cpc_extended_8f);
tone(8, 196, 500);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Sto"); // draw the time string to the display
u8g2.sendBuffer();
delay(500);
tone(8, 165, 500);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Lat"); // draw the time string to the display
u8g2.sendBuffer();
delay(500);
tone(8, 196, 500);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Sto"); // draw the time string to the display
u8g2.sendBuffer();
delay(500);
tone(8, 165, 500);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Lat"); // draw the time string to the display
u8g2.sendBuffer();
delay(500);
tone(8, 196, 500);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Niech"); // draw the time string to the display
u8g2.sendBuffer();
delay(500);
tone(8, 220, 250);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Zy"); // draw the time string to the display
u8g2.sendBuffer();
delay(250);
tone(8, 196, 250);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "je"); // draw the time string to the display
u8g2.sendBuffer();
delay(250);
tone(8, 175, 250);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Zy"); // draw the time string to the display
u8g2.sendBuffer();
delay(250);
tone(8, 165, 250);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "je"); // draw the time string to the display
u8g2.sendBuffer();
delay(250);
tone(8, 175, 1250);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Nam"); // draw the time string to the display
u8g2.sendBuffer();
delay(1250);
//-----------------
tone(8, 175, 500);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Sto"); // draw the time string to the display
u8g2.sendBuffer();
delay(500);
tone(8, 147, 500);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Lat"); // draw the time string to the display
u8g2.sendBuffer();
delay(500);
tone(8, 175, 500);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Sto"); // draw the time string to the display
u8g2.sendBuffer();
delay(500);
tone(8, 147, 500);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Lat"); // draw the time string to the display
u8g2.sendBuffer();
delay(500);
tone(8, 175, 500);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Niech"); // draw the time string to the display
u8g2.sendBuffer();
delay(500);
tone(8, 196, 250);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Zy"); // draw the time string to the display
u8g2.sendBuffer();
delay(250);
tone(8, 175, 250);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "je"); // draw the time string to the display
u8g2.sendBuffer();
delay(250);
tone(8, 165, 250);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Zy"); // draw the time string to the display
u8g2.sendBuffer();
delay(250);
tone(8, 147, 250);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "je"); // draw the time string to the display
u8g2.sendBuffer();
delay(250);
tone(8, 165, 1250);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Nam"); // draw the time string to the display
u8g2.sendBuffer();
delay(1250);
//-----------------
tone(8, 196, 250);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Jesz"); // draw the time string to the display
u8g2.sendBuffer();
delay(250);
tone(8, 196, 250);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "cze"); // draw the time string to the display
u8g2.sendBuffer();
delay(250);
tone(8, 165, 500);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "raz"); // draw the time string to the display
u8g2.sendBuffer();
delay(500);
tone(8, 196, 250);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Jesz"); // draw the time string to the display
u8g2.sendBuffer();
delay(250);
tone(8, 196, 250);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "cze"); // draw the time string to the display
u8g2.sendBuffer();
delay(250);
tone(8, 165, 500);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "raz"); // draw the time string to the display
u8g2.sendBuffer();
delay(500);
tone(8, 196, 500);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Niech"); // draw the time string to the display
u8g2.sendBuffer();
delay(500);
tone(8, 262, 250);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Zy"); // draw the time string to the display
u8g2.sendBuffer();
delay(250);
tone(8, 247, 250);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "je"); // draw the time string to the display
u8g2.sendBuffer();
delay(250);
tone(8, 220, 250);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Zy"); // draw the time string to the display
u8g2.sendBuffer();
delay(250);
tone(8, 208, 250);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "je"); // draw the time string to the display
u8g2.sendBuffer();
delay(250);
tone(8, 220, 1250);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Nam"); // draw the time string to the display
u8g2.sendBuffer();
delay(1250);
//-----------------
tone(8, 247, 1250);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "A"); // draw the time string to the display
u8g2.sendBuffer();
delay(1250);
tone(8, 247, 500);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Kto?"); // draw the time string to the display
u8g2.sendBuffer();
delay(500);
tone(8, 247, 500);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Ki"); // draw the time string to the display
u8g2.sendBuffer();
delay(500);
tone(8, 262, 1250);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, " nga"); // draw the time string to the display
u8g2.sendBuffer();
delay(60000);
};
void cotam(){
u8g2.setFont(u8g2_font_amstrad_cpc_extended_8f);
// play e4
delay(600);
tone(8, 329.63, 300);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Ro"); // draw the time string to the display
u8g2.sendBuffer();
delay(350);
// play d4#
tone(8, 311.13, 300);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Czni"); // draw the time string to the display
u8g2.sendBuffer();
delay(350);
// play e4
tone(8, 329.63, 300);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Ca"); // draw the time string to the display
u8g2.sendBuffer();
delay(350);
// play d4#
tone(8,311.13, 300);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Ko"); // draw the time string to the display
u8g2.sendBuffer();
delay(350);
// play e4
tone(8, 329.63, 300);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Ko"); // draw the time string to the display
u8g2.sendBuffer();
delay(350);
// play b3
tone( 8, 246.94, 300);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Ko"); // draw the time string to the display
u8g2.sendBuffer();
delay(400);
// play d4
tone(8, 293.66,300);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Cham"); // draw the time string to the display
u8g2.sendBuffer();
delay(400);
// play c4
tone(8, 261.63,300);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Cham"); // draw the time string to the display
u8g2.sendBuffer();
delay(400);
// play a3
tone(8, 220, 900);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Cham"); // draw the time string to the display
u8g2.sendBuffer();
delay(1000);
// play d3
tone(8,146.83, 300);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Cie"); // draw the time string to the display
u8g2.sendBuffer();
delay(350);
//play f3
tone(8, 174.61, 300);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Cie"); // draw the time string to the display
u8g2.sendBuffer();
delay(400);
//play a3
tone(8, 220, 300);
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, "Cie"); // draw the time string to the display
u8g2.sendBuffer();
delay(400);
// play b3
tone(8, 246.94, 900);
delay(60000);
// play f3
}
void showMenu(){
boolean menu = true;
while(menu){
int value = analogRead(A2);
if(value<204){
u8g2.setFont(u8g2_font_amstrad_cpc_extended_8f);
for(int i = 0;i<68;i++){
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(-i, 8, "Aktywuj budzik"); // draw the time string to the display
u8g2.sendBuffer(); // transfer internal memory to the display
byte buttonValue = digitalRead(6);
if (buttonValue == LOW) {
tone(8, 262, 50);
while(buttonValue == LOW){
buttonValue = digitalRead(6);
}
aktywujBudzik();
}
if(!menu ||analogRead(A2)>204) i=1000;
else delay(100);
}
}
else if(value<408){
u8g2.setFont(u8g2_font_amstrad_cpc_extended_8f);
for(int i = 0;i<68;i++){
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(-i, 8, "Edytuj Budzik"); // draw the time string to the display
u8g2.sendBuffer(); // transfer internal memory to the display
byte buttonValue = digitalRead(6);
if (buttonValue == LOW) {
tone(8, 262, 50);
while(buttonValue == LOW){
buttonValue = digitalRead(6);
}
edytujBudziki();
}
if(!menu || analogRead(A2)>408||analogRead(A2)<204) i=1000;
else delay(100);
}
}
else if(value<612){
u8g2.setFont(u8g2_font_amstrad_cpc_extended_8f);
for(int i = 0;i<68;i++){
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(-i, 8, "Wycisza"); // draw the time string to the display
u8g2.sendBuffer(); // transfer internal memory to the display
byte buttonValue = digitalRead(6);
if (buttonValue == LOW) {
tone(8, 262, 50);
while(buttonValue == LOW){
buttonValue = digitalRead(6);
delay(10);
}
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(0, 8, " "); // draw the time string to the display
u8g2.sendBuffer(); // transfer internal memory to the display
while(buttonValue == HIGH){
buttonValue = digitalRead(6);
delay(10);
}
tone(8, 262, 50);
while(buttonValue == LOW){
buttonValue = digitalRead(6);
delay(10);
}
delay(100);
}
if(analogRead(A2)>612||analogRead(A2)<408) i=1000;
else delay(100);
}
}
else if(value<816){
u8g2.setFont(u8g2_font_amstrad_cpc_extended_8f);
for(int i = 0;i<68;i++){
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(-i, 8, "Mini Gra Lot"); // draw the time string to the display
u8g2.sendBuffer(); // transfer internal memory to the display
byte buttonValue = digitalRead(6);
if (buttonValue == LOW) {
tone(8, 262, 50);
while(buttonValue == LOW){
buttonValue = digitalRead(6);
}
graLot();
}
if(!menu || analogRead(A2)>816||analogRead(A2)<612) i=1000;
else delay(100);
}
}
else{
u8g2.setFont(u8g2_font_amstrad_cpc_extended_8f);
for(int i = 0;i<68;i++){
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(-i, 8, "Cofnij Back"); // draw the time string to the display
u8g2.sendBuffer(); // transfer internal memory to the display
byte buttonValue = digitalRead(6);
if (buttonValue == LOW) {
tone(8, 262, 50);
while(buttonValue == LOW){
buttonValue = digitalRead(6);
}
menu=false;
}
if(!menu || analogRead(A2)<816) i=1000;
else delay(100);
}
}
}
delay(300);
}
void ring(int i){
byte buttonValue = digitalRead(6);
while(buttonValue == HIGH){
buttonValue = digitalRead(6);
tone(8, random(100, 600), 500);
delay(500);
}
budziki[i].aktywny=false;
while(buttonValue == LOW){
buttonValue = digitalRead(6);
delay(10);
}
}
void setup() {
Serial.begin(9600);
pinMode(8, OUTPUT);
pinMode(A2, INPUT);
pinMode(6, INPUT_PULLUP);
u8g2.begin();
u8g2.setContrast(200);
if (! rtc.begin()) { // start the RTC module
abort();
}
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
void loop() {
//Serial.println(budziki[2].godzina);
int value = analogRead(A2);
byte buttonValue = digitalRead(6);
DateTime now = rtc.now();
for(int i=0;i<10;i++){
if(budziki[i].godzina == now.hour() && budziki[i].minuta == now.minute() && budziki[i].aktywny){
ring(i);
}
}
if(now.month()==10 && now.day()==27 && now.hour()==23 && now.minute()==45){
stoLat();
}
if(now.month()==8 && now.day()==22 && now.hour()==0 && now.minute()==0){
cotam();
}
if(now.minute()==0 && now.second()<1){
showtrue();
}
if (buttonValue == LOW) {
tone(8, 262, 50);
while(buttonValue == LOW){
buttonValue = digitalRead(6);
};
showMenu();
}
else{
if(value<512){
DateTime now = rtc.now(); // get current time
if(now.second()%2==0)sprintf(time_string, "%02d:%02d", now.hour(), now.minute()); // add hours, colon symbol and minutes into a string
else sprintf(time_string, "%02d %02d", now.hour(), now.minute()); // add hours, colon symbol and minutes into a string
u8g2.setFont(u8g2_font_t0_11b_tn); // choose a suitable font
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(2, 8, time_string); // draw the time string to the display
u8g2.sendBuffer(); // transfer internal memory to the display
delay(100); // wait
}
else if(value<1000){
DateTime now = rtc.now(); // get current time
sprintf(time_string, "%02d.%02d", now.month(), now.day());
u8g2.setFont(u8g2_font_t0_11b_tn); // choose a suitable font
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(2, 8, time_string); // draw the time string to the display
u8g2.sendBuffer(); // transfer internal memory to the display
delay(100); // wait
}
else{
DateTime now = rtc.now(); // get current time
sprintf(time_string, "%04d", now.year());
u8g2.setFont(u8g2_font_t0_11b_tn); // choose a suitable font
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(4, 8, time_string); // draw the time string to the display
u8g2.sendBuffer(); // transfer internal memory to the display
delay(100); // wait
}
}
}