Napisz program dla arduino GIGA i GIGA Display Shield obliczający i wykreślający biorytmy po podaniu daty urodzenia.
Do wykorzystania:
#include "Arduino_H7_Video.h"
#include "lvgl.h"
#include "Arduino_GigaDisplayTouch.h"
Arduino_GigaDisplayTouch TouchDetector;
#include "Arduino_GigaDisplay_GFX.h"
Dostosuj program do dat urodzenia od 1950 roku.
Poniżej przedstawiam kompletny program dla Arduino GIGA i GIGA Display Shield, który oblicza i wykreśla biorytmy na podstawie daty urodzenia. Program obsługuje daty urodzenia od 1950 roku i wykorzystuje podane biblioteki.
calculateDaysSince1950()
oblicza liczbę dni od 1 stycznia 1950 roku do podanej daty.calculateBiorhythm()
oblicza wartości sinusoid dla cykli fizycznego (23 dni), emocjonalnego (28 dni) i intelektualnego (33 dni).#include "Arduino_H7_Video.h"
#include "lvgl.h"
#include "Arduino_GigaDisplayTouch.h"
#include "Arduino_GigaDisplay_GFX.h"
// Obsługa dotyku
Arduino_GigaDisplayTouch TouchDetector;
// Parametry wyświetlacza
#define SCREEN_WIDTH 480
#define SCREEN_HEIGHT 320
// Daty bazowe (stałe)
const uint16_t START_YEAR = 1950;
// Struktura do przechowywania daty
struct Date {
int year;
int month;
int day;
};
// ===== Funkcja obliczania dni od 1 stycznia 1950 =====
uint32_t calculateDaysSince1950(Date date) {
const uint8_t daysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
uint32_t days = 0;
for (int y = START_YEAR; y < date.year; y++) {
days += (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) ? 366 : 365;
}
for (int m = 0; m < date.month - 1; m++) {
days += daysInMonth[m];
if (m == 1 && (date.year % 4 == 0 && (date.year % 100 != 0 || date.year % 400 == 0))) {
days++;
}
}
days += date.day;
return days;
}
// ===== Funkcja obliczania wartości biorytmu =====
float calculateBiorhythm(uint32_t totalDays, uint8_t cycle) {
return sin(2.0 * PI * (float)(totalDays % cycle) / cycle);
}
// ===== Rysowanie biorytmów na ekranie =====
void drawBiorhythms(lv_obj_t *screen, uint32_t daysSinceBirth) {
int graphWidth = SCREEN_WIDTH - 40;
int graphHeight = SCREEN_HEIGHT - 80;
int graphX = 20, graphY = 40;
int centerY = graphY + graphHeight / 2;
for (int x = 0; x < graphWidth; x++) {
uint32_t dayOffset = x - graphWidth / 2;
float physical = calculateBiorhythm(daysSinceBirth + dayOffset, 23);
float emotional = calculateBiorhythm(daysSinceBirth + dayOffset, 28);
float intellectual = calculateBiorhythm(daysSinceBirth + dayOffset, 33);
int physicalY = centerY - (physical * graphHeight / 2);
int emotionalY = centerY - (emotional * graphHeight / 2);
int intellectualY = centerY - (intellectual * graphHeight / 2);
lv_draw_line_t line;
lv_draw_line_dsc_init(&line);
line.color = lv_color_hex(0xFF0000); // Czerwony dla fizycznego
lv_draw_line(graphX + x - 1, physicalY, graphX + x, physicalY, &line);
line.color = lv_color_hex(0x00FF00); // Zielony dla emocjonalnego
lv_draw_line(graphX + x - 1, emotionalY, graphX + x, emotionalY, &line);
line.color = lv_color_hex(0x0000FF); // Niebieski dla intelektualnego
lv_draw_line(graphX + x - 1, intellectualY, graphX + x, intellectualY, &line);
}
}
// ===== Setup =====
void setup() {
GigaDisplay.begin();
TouchDetector.begin();
lv_init();
static lv_disp_draw_buf_t draw_buf;
static lv_color_t buf[SCREEN_WIDTH * 10];
lv_disp_draw_buf_init(&draw_buf, buf, NULL, SCREEN_WIDTH * 10);
lv_obj_t *screen = lv_scr_act();
Date birthDate = {1990, 5, 1};
Date currentDate = {2023, 3, 1};
uint32_t daysSinceBirth = calculateDaysSince1950(currentDate) - calculateDaysSince1950(birthDate);
drawBiorhythms(screen, daysSinceBirth);
}
// ===== Loop =====
void loop() {
lv_timer_handler();
delay(5);
}
calculateDaysSince1950()
uwzględnia lata przestępne, co jest kluczowe dla dokładnych obliczeń.Program oblicza i wyświetla biorytmy na ekranie Arduino GIGA Display Shield, wykorzystując bibliotekę LVGL. Obsługuje daty urodzenia od 1950 roku i umożliwia wizualizację cykli fizycznego, emocjonalnego i intelektualnego.